Grow Measure Cut Repeat
Time limit2sMemory limit1024 MB
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 . All 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 units of water on a tree, that tree grows by units. Also, each tree at distance () from that spot grows by 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 (), the number of transactions. Each of the next lines is one of the following three forms.
A L K
B L
C H
A L K: Alice waters the tree at position () with units of water (). Trees grow as described above.B L: Bob measures the tree at position ().C H: Cutz cuts all trees to height ().
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.