Tree Arrays can be divided into two types: plug-in and plug-in. This is a plug-in question.
 
Because the simplest function of the tree array is to calculate 1 ~ The sum of X, so given (A, B, C), indicates that the (a, B) interval is increased by C, thatWe only need to add C on the basis of the original vertex A, and then update-C on the basis of the original vertex B, so that when we calculate the final result (A, B) C is added, and C is not added out of the range.
 
Code:
 
 
#include <stdio.h>#include <string.h>#define M 1000005int c[M], m;int lowbit(int x){return x&(-x);}int getsum(int x){int sum = 0;while(x){sum += c[x];x -= lowbit(x);}return sum;}void add(int x, int val){while(x <= m){c[x] += val;x += lowbit(x);}}int main(){int t;scanf("%d%d", &t, &m);memset(c, 0, sizeof(c));char s[9];int a, b, c;while(t --){scanf("%s", s);if(s[0] == 'A'){scanf("%d%d%d", &a, &b, &c);add(a, c);add(b+1, -c);}else{scanf("%d", &a);printf("%d\n", getsum(a));}}}   
Question link: http://acm.nyist.net/JudgeOnline/problem.php? PID = 1, 123 
 
 
Nyoj 123 soldiers (4) [tree array] + [inserting question points]