South Generals have n soldiers, numbered 1 to N, each of these soldiers is known for their kills.
The staff is the South General's military advisers, the South General often want to know the number m to nth soldier's total kills, please help the handyman to answer the South General.
The South General's inquiry after the soldier I may also kill the Q person, after the South General asked again, need to consider the new kill number.
-
-
Input
-
-
only one set of test data
The first line is two integer n,m, where N represents the number of soldiers (1<n<1000000), and M represents the number of instructions. (1<m<100000)
The next line is n integers, and AI represents the number of soldier kills. (0<=ai<=100)
The subsequent M-line is an instruction that contains a string and two integers, first a string, and if the string query indicates that the South General has a query operation, followed by the two integer m,n, indicating the start and end of the query soldier number; If the string add is followed by the two integer I , A (1<=i<=n,1<=a<=100), which indicates that the number of new kills for the first soldier is a.
<span style= "color: #330033;" >//single point update, Interval summation # include <stdio.h> #include <string.h> #include <algorithm>using namespace Std;const int N = 1e6+5;struct tree{int l,r; int num;} t[4*n];void Build (int l,int r,int root) {t[root].l=l; T[root].r=r; t[root].num=0; if (l==r) {return; } int mid= (L+R)/2; Build (L,mid,2*root); Build (mid+1,r,2*root+1);} void update (int val,int id,int root) {if (t[root].l==t[root].r&&t[root].l==id) {t[root].num+=val; Return } int mid= (T[ROOT].L+T[ROOT].R)/2; if (id<=mid) update (val,id,2*root); else update (VAL,ID,2*ROOT+1); T[root].num=t[2*root].num+t[2*root+1].num;} int ans;void find (int l,int r,int root) {if (t[root].l==l&&t[root].r==r) {ans+=t[root].num; Return } int mid= (T[ROOT].L+T[ROOT].R)/2; if (R<=mid) find (L,r,2*root); else if (l>mid) find (l,r,2*root+1); else{find (L,mid,2*root); FinD (mid+1,r,2*root+1); }}int Main () {int n,m,i,j; while (~SCANF ("%d%d", &n,&m)) {build (1,n,1); for (i=1;i<=n;i++) {int x; scanf ("%d", &x); Update (x,i,1); } Char s[10]; while (m--) {int x,y;scanf ("%s", s); scanf ("%d%d", &x,&y); if (s[0]== ' A ') update (y,x,1); else{ans=0; Find (x,y,1); printf ("%d\n", ans); }}} return 0;} </span>