Problem10298--CF EDU - Segment Tree P2 - Step 4 - F. Mountain

10298: CF EDU - Segment Tree P2 - Step 4 - F. Mountain

[Creator : ]
Time Limit : 5.000 sec  Memory Limit : 512 MiB

Description

And this is a problem from IOI 2005, which is also solved using a segment tree

The Mountain Amusement Park has opened a brand-new simulated roller coaster. The simulated track consists of $n$ rails attached end-to-end with the beginning of the first rail fixed at elevation 0. Byteman, the operator, can reconfigure the track at will by adjusting the elevation change over a number of consecutive rails. The elevation change over other rails is not affected. Each time rails are adjusted, the following track is raised or lowered as necessary to connect the track while maintaining the start at elevation 0.

Each ride is initiated by launching the car with sufficient energy to reach height $h$. That is, the car will continue to travel as long as the elevation of the track does not exceed $h$, and as long as the end of the track is not reached.

Given the record for all the day's rides and track configuration changes, compute for each ride the number of rails traversed by the car before it stops.

Internally, the simulator represents the track as a sequence of $n$ elevation changes $d_i$. Initially the rails are horizontal; that is, $d_i=0$ for all $i$.


Rides and reconfigurations are interleaved throughout the day. Each reconfiguration is specified by three numbers: $a, b, D$. The segment to be adjusted consists of rails $a$ through $b$ (inclusive). The elevation change over each rail in the segment is set to $D$.


Each ride is specified by one number $h$ — the maximum height that the car can reach.

Input

The first line contains an integer $n\ (1≤n≤10^9)$, the number of rails. The following lines contain three kinds of queries:
  • I a b D: configuration change. The rails from $a$-th to $b$-th inclusive after the execution of the request have an elevation equal to $D$.
  • Q h: start the ride. It is required to find the number of rails that the trolley will pass, which is able to rise to the height $h$.
  • E: end of input. This request will appear exactly once at the end of the file.
At any given time, the height of any point on the track is in the range from $0$ to $10^9$. The input contains no more than 100,000 lines.

Output

For each query $Q$ print a single integer: the number of rails that the trolley will pass.

Sample 1 Input

4
Q 1
I 1 4 2
Q 3
Q 1
I 2 2 -1
Q 3
E

Sample 1 Output

4
1
0
3

HINT

CF EDU.

Source/Category