Rectangle Painting
Time limit12sMemory limit1024 MB
Paint horizontal runs of cells black on an infinite grid, and report the tallest height h such that some column in a range is black from y=0 up to h, with queries encrypted online.
- Level
Hard8 of 10
- Topics
- Segment tree, Implementation
- Solved
- No attempts yet
Statement
There is an infinite grid that extends to the left, to the right, and upward. Every cell with and exists. Initially all cells are white. You have to process queries of two types:
- : paint all cells with black. A cell that is already black keeps its color.
- : consider all cells whose coordinate lies in . Find the highest cell such that all cells exactly under it are black. Formally, find the maximal such that there exists where, for all , the cell is black.
Queries are encrypted with the answers to earlier queries, so they must be processed online.
Input
The first line contains one integer (), the number of queries.
Each of the next lines contains an encrypted query. Let be the sum of the answers to all queries of the second type processed so far. Each query has one of the forms or . The decrypted values satisfy and . The input values may not fit in 32-bit integers.
Add each new answer to after processing a query of the second type.
Output
For each query of the second type, print the answer on a separate line.
Hint
