[Line Segment tree] Line Segment Tree Series 0.1 Single Point modification Single Point summation line segment tree

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.