Shooting on the array
All submissions for this problem are available.
You have an array A of length N consisting of positive integers. Let's consider N vertical segments (parallel to y axis) on the plane, the i-th segment connects the points (i, 0) and (i, Ai).
You have Q queries of following two types:
- + i X : Ai += X
- ? i L R : Let's consider R - L+ 1 rays which are parallel to x axis. The j-th ray eminates at point (i - 0.5, L+ j - 1.5) and extends to the right infinitely long parallel to x axis. You have to print the number of the segments that will be shot by some ray. If a ray shoots a segment then it stops at that point and does't extend further.
Note that all the queries of the second type are independent of each other.
The first line of the input contains an integer T denoting the number of tests
The first line of each test case consists of two space separated integers N, Q .
The second line contains N space separated denoting the array A.
Next Q lines contain the description of the queries in the format above.
After each query of the second type, output in a single line the number of segments that are shot.
- 1 ≤ T ≤ 100
- 1 ≤ N ≤ 106
- 1 ≤ Q ≤ 105
- 0 < X ≤ 10,000
- 1 ≤ i ≤ N
- 1 ≤ Ai ≤ 109
- 1 ≤ L ≤ R ≤ 109
- The sum of N over all testcases does not exceed 106
- The sum of Q over all testcases does not exceed 105
- Subtask #1 (10 points) : There are only queries of the second type
- Subtask #2 (10 points) : In all queries of the second type i = 1
- Subtask #3 (30 points) : The sum of Q over all testcases does not exceed 104
- Subtask #4 (50 points) : Original constraints
Input: 1 6 4 3 7 2 4 8 7 ? 4 3 9 ? 3 1 7 + 6 2 ? 4 3 9 Output: 2 3 3
|Tags||altruist_, medium-hard, oct17, segment-tree|
|Time Limit:||3 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.