spoj#NAJHQ. Hazzat’s Query
Hazzat’s Query
Hazzat is a new guys in computer science. Now he read in 4rd semester. Recently he completed the course data structure. After finished data structure course he can realize that those are not enough for his. Every day he fall in a new (data structure) problem and want solve it, but those problem he can’t solve using his know data structure. He want to establish new data structure. But he always failed to establish it. Now help hazzat to establish a new data structure following problems.
Today Hazzat problem is-
Given a N size Array (arr[N]) initialize all the element value is exactly c.
see the pseudo
for(i=1;i<=N;i++)
arr[i]=c;
Today Hazzat want to do 6 types of task.
i) add exactly k value from array index u to v
see the pseudo
for(i=u;i<=v;i++)
arr[i]=arr[i]+k;
ii) minus exactly k value from array index u to v
see the pseudo
for(i=u;i<=v;i++)
arr[i]=arr[i]-k;
iii) add exactly k value only array index u
see the pseudo
arr[u]=arr[u]+k;
iv) minus exactly k value only array index u
see the pseudo
arr[u]=arr[u]-k;
v) reset a array index u with k value
see the pseudo
arr[u]= k;
vi) find the current value of array index u
see the pseudo
print arr[u];
Here the array is 1 base index.
Input:
Input start with an integer number T(≤10), which is number of test cases.
For each test case
First line given
N Q c where N is array size, Q number of queries and c is the initialize value of array.
Next Q line give the Hazzat task’s
add u v k (add exactly k values from array index u to v)
minus u v k (minus exactly k values from array index u to v)
addin u k (add exactly k value only array index u)
minusin u k (minus exactly k value only array index u)
reset u k (reset a array index u with k value)
find u (print current value of array index u)
Constrains:
- T≤10
- 1 ≤ N, Q ≤10^5
- 1≤ u ≤ v≤N
- 0≤c,k≤10^9
Output:
For each case, Print “Case #X” where X is case number.
After Next line print value of array index u where hazzat want to know. (only for find u task)
There will be a blank line between two case.
Sample:
Input |
Output |
2 |
Case #1 |
Output number may be Negetive.
Data set is so huge. Use faster I/O