Finally, we have fixed the single point of failure to modify the line segment tree... 3 months .. Fuck .. There is no template question at all .. I think it's too weak... Quail eggs... I must update my version further.
# Include <iostream> # include <cstdlib> # include <cstdio> # include <cmath> using namespace STD; struct node {int left, right, value ;}; node point [100]; int father [100]; int g; void buildtree (int I, int left, int right) {FATHER [I] = (INT) floor (I) /2.0; point [I]. left = left; point [I]. right = right; point [I]. value = 0; If (Left = right) {FATHER [I] = I;} else {buildtree (I <1, left, (INT) floor (right + Left)/2.0); buildtree (I <1) + 1, (INT) floor (right + Left)/2.0) + 1, right) ;}}// synchronized void Update (int x, int add, int left, int right, int now) // left, right is the range, and add is the added value, now is the label of the current node, and X is the target node {int mid = (left + right)> 1; point [now]. value + = add; If (right-left) <1) {G = left; return;} If (left <= x) & (x <= mid )) {Update (x, add, left, mid, 2 * Now);} If (Mid + 1) <= x) & (x <= right )) {Update (x, add, Mid + 1, right, 2 * Now + 1) ;}// -------------------------------------------------------------------------------- int search (int x, int now) {If (point [now]. left = point [now]. right) {return (point [now]. value);} int mid = (point [now]. left + point [now]. right)> 1; if (point [now]. left <= x) & (x <= mid) {return (search (x, 2 * Now);} If (Mid + 1) <= X) & (x <= point [now]. right) {return (search (x, 2 * Now + 1);} return 598460606;} // returns int main () {int n, m, K; cin> N; buildtree (1, 1, n); For (INT I = 1; I <= N; I ++) {int X, AD; cin> x> ad; Update (x, AD, 1, n, 1);} CIN> m; For (INT I = 1; I <= m; I ++) {int X, AD; CIN> x> ad; Update (x, AD, 1, n, 1);} CIN> K; for (INT I = 1; I <= K; I ++) {int s; CIN> S; cout <search (s, 1) <Endl ;}}
[Line Segment tree] Line Segment Tree Series 0.1 Single Point modification Single Point summation line segment tree