Under construction

Still being built. Things may change

Stacking Sticks

Interview

Time limit1sMemory limit512 MB

Summary
Drop 1x4 horizontal and 4x1 vertical blocks onto columns, then report the highest block height at a given x coordinate.
Level

Medium5 of 10

Topics
Segment tree, Sorting, Simulation
Solved
No attempts yet

Statement

Satori is playing a stacking game with horizontal 1×41 \times 4 blocks and vertical 4×14 \times 1 blocks. Once you choose where a block lands, it falls straight down. If part of the bottom face of a falling block touches the top face of another block or the floor, the block stops. Blocks that are next to each other horizontally may pass by each other while falling.

Write a program that handles the following queries.

  • 1 i: Drop a horizontal 1×41 \times 4 block so that its left end cell is at x=ix = i.
  • 2 i: Drop a vertical 4×14 \times 1 block so that it is at x=ix = i.
  • 3 i: Print the maximum yy coordinate of the blocks at x=ix = i. If no block exists at that xx coordinate, print 00.

Input

The first line contains the number of queries QQ. (1≤Q≤150 000)(1 \leq Q \leq 150\,000)

The next QQ lines each contain one query. Query type 3 appears at least once. (−109≤i≤109, i(-10^9 \leq i \leq 10^9,\ i is an integer))

Output

For each query of type 3, print the answer on its own line.

Examples1

  1. Example 1

    Input
    5
    1 1
    2 3
    1 2
    3 1
    3 5
    
    Expected output
    1
    6