Hide

Problem A
Points of Snow

Lineland is an infinitesimal country primarily known for its 1-dimensional layout. However, it is also true that Lineland provides some truly excellent skiing opportunities for beginners.

You are running a snow depth information service that answers queries about how deep the snow is at various locations in Lineland. As your service is becoming increasingly popular, you realize that the traditional way of answering queries (i.e. by going on a ski trip to make a manual measurement) does not scale.

In order to speed things up, you made a deal with the national wheather forcaster. They have agreed to give you notice whenever snow falls or melts away across different strecthes of the country. What remains is to write a program that can answer incoming queries from the public automatically, provided the information from the wheather forcaster.

Input

The first line contains three integers N, K and Q, indicating respectively the length of Lineland (in km), the number of wheather reports you receive over the course of the year, and the number of snow depth queries you get. The next K+Q lines describes, in chronological order, either a snowfall or a melting incident for some segment of the country, or a query requesting to know the snow depth at some location.

The i’th such line begins with a characther Ci{!,?}. If Ci=!, then three integers will follow, Li, Ri and Di, meaning that the snow level rose with Di cm in the area between the Li’th and the Ri’th km mark of Lineland. For snowfalls Di is positive, whereas for melting incidents, Di is negative.

If Ci=?, then a single integer Xi will follow on the same line, indicating a query requsting to know the snow depth in the middle of the Xi’th km of Lineland (e.g. if Xi=1, then you should report the snow depth at distance 0.5km from the beginning of Lineland). The input will always adhere to the following constraints:

  • 1N1000000

  • 1K,Q100000

  • 0Li<RiN

  • 100000Di100000

  • 1XiN

The snow level will at no point in time nor space be negative, e.g. for every location x, 0x<N and every time k, 0k<K it holds that i=0k{DiLix<Ri}0. At the beginning of the year, there is no snow; however, there might be snow left at the end of the year.

Output

Output Q lines, one for each query, reporting the snow depth (in cm) at the requested location.

Sample Input 1 Sample Output 1
10 4 2
! 0 6 3
! 3 9 5
? 6
! 2 7 -2
! 5 7 1
? 7
8
4
Hide

Please log in to submit a solution to this problem

Log in