Fortress Destruction
Time limit1sMemory limit512 MB
Given N nested blocks forming a fortress and Q missile strikes, output how many blocks each strike destroys from the top of its column, in firing order.
- Level
Medium7 of 10
- Topics
- Segment tree, Tree, Implementation
- Solved
- No attempts yet
Problem
blocks are stacked to build a fortress. Each block occupies the interval from column to column on floor , and no two blocks overlap. Every block above floor 1 has at least one block directly below it. A block stacked on top lies entirely within the interval of the block below it. That is, for any block stacked on block , holds.

To destroy this fortress, missile strikes are fired. Each strike fires a missile with power at position , and it destroys up to blocks from the top among the blocks at column of the fortress. If a block underneath is removed during this process, the block above it falls down without damage.
The following figure shows a missile fired at with .

For each strike, in the order they were fired, find the number of blocks destroyed.
Input
The first line contains the number of blocks . ()
The next lines each contain the information of a block that makes up the fortress: , , and . (, )
The next line contains the number of strikes . ()
The next lines each contain the position and power of a strike. (, )
Output
For each strike, in the order they were fired, print the number of blocks destroyed.