#P10130. Chain-Linked Ships and Burning Soldiers

    ID: 12118 Type: Default 1000ms 256MiB

Chain-Linked Ships and Burning Soldiers

Chain-Linked Ships and Burning Soldiers

We are given $$n$$ ships numbered from $$1$$ to $$n$$, each with $$m$$ soldiers numbered from $$1$$ to $$m$$. Initially, there are $$s$$ groups of chains that connect portions of ships. For each group, you are given four integers $$l_1, r_1, l_2, r_2$$ which indicates that for every $$k$$ with $$0 \le k \le r_1 - l_1$$, ship $$(l_1+k)$$ is connected to ship $$(l_2+k)$$. It is guaranteed that $$r_1 - l_1 + 1 = r_2 - l_2 + 1$$ and $$l_1 < l_2$$. Moreover, for any ship $$p$$, there exists at most one relation such that $$l_2 \le p \le r_2$$.

After the initial setup, there are $$q$$ operations performed in order (numbered from $$1$$ to $$q$$):

  1. Operation 1: Given in the format 1 p L R. Shoot a rocket at ship $$p$$ targeting soldiers in the range $$[L,R]$$. As a consequence of the chain connections, every soldier in $$[L,R]$$ on all ships that are directly or indirectly connected to ship $$p$$ will be set on fire. Note that a soldier may be set on fire multiple times.

  2. Operation 2: Given in the format 2 p. This operation revokes (cancels) the effect of the previously performed Operation 1 with operation id $$p$$. After revocation, its effect is completely removed from subsequent queries.

  3. Operation 3: Given in the format 3 p L R. Query whether all soldiers in the range $$[L,R]$$ on ship $$p$$ are on fire. Output Yes if all soldiers in the range are on fire, otherwise output No.

inputFormat

The first line contains four integers $$n$$, $$m$$, $$s$$, $$q$$ — the number of ships, the number of soldiers per ship, the number of chain relations, and the number of operations, respectively.

Then follow $$s$$ lines, each containing four integers: $$l_1$$, $$r_1$$, $$l_2$$, $$r_2$$ representing a chain relation. Each relation indicates that for every $$k$$ in $$[0, r_1-l_1]$$, ship $$(l_1+k)$$ is connected to ship $$(l_2+k)$$.

Then follow $$q$$ lines, each representing an operation. The operations can be in one of the following formats:

  • For Operation 1: 1 p L R
  • For Operation 2: 2 p (where $$p$$ is the id of a previous Operation 1)
  • For Operation 3: 3 p L R

outputFormat

For each Operation 3, output a single line containing either Yes or No depending on whether all soldiers in the specified range are on fire.

sample

3 5 1 5
1 1 2 2
1 1 1 3
3 2 1 3
2 1
3 2 1 3
3 1 1 5
Yes

No Yes

</p>