Under construction

Still being built. Things may change

Grow Measure Cut Repeat

Time limit2sMemory limit1024 MB

Summary
Process a sequence of tent-shaped watering updates, height caps, and point queries on 100000 trees, printing each measured height.
Level

Hard8 of 10

Topics
Segment tree, Implementation, Math
Solved
No attempts yet

Problem

The UCF Programming Team Coaches are the most experienced coaching group in the world. They are also concerned about the forests of our planet disappearing. The coaches started a 1-D forest. They planted a tree seed at each integer position from 1 to 10510^5. All 10510^5 trees start at height 0. The coaches recruited three forest rangers, Alice, Bob, and Cutz, to maintain this forest. Once you see their power, the rangers are almost like fairies!

Alice likes to watch trees grow. She received a magical watering pot. When she pours KK units of water on a tree, that tree grows by KK units. Also, each tree at distance DD (D<KD < K) from that spot grows by K−DK-D units.

Bob likes to climb trees. He has a special tape that can measure the height of any tree.

Cutz likes to cut all trees in the forest down to a specific height. Taller trees are cut to the new height, and shorter trees are not affected. Cutz picks a threshold (the maximum height), and every tree taller than that threshold is cut to exactly that height. Cutz likes decreasing sequences, so each cut is at a lower height than the previous cut, except for the first cut.

For a list of commands from Alice, Bob, and Cutz, find the height that Bob measures in each of his commands. All trees start at height 0.

Input

The first line contains an integer tt (1≤t≤2×1051 \le t \le 2 \times 10^5), the number of transactions. Each of the next tt lines is one of the following three forms.

A L K
B L
C H
  • A L K: Alice waters the tree at position LL (1≤L≤1051 \le L \le 10^5) with KK units of water (1≤K≤1061 \le K \le 10^6). Trees grow as described above.
  • B L: Bob measures the tree at position LL (1≤L≤1051 \le L \le 10^5).
  • C H: Cutz cuts all trees to height HH (1≤H≤1081 \le H \le 10^8).

Output

Alice and Cutz transactions produce no output. For each Bob transaction (B L), print the height of the tree that Bob measured on its own line.

Examples2

  1. Example 1

    Input
    6
    A 7 5
    B 6
    C 4
    A 5 4
    B 6
    B 7
    
    Expected output
    4
    7
    6
    
  2. Example 2

    Input
    7
    A 10 8
    B 10
    C 6
    A 10 8
    C 4
    B 3
    B 5
    
    Expected output
    8
    2
    4