South generals have millions of troops, now known to have a total of M soldiers, numbered 1~m, each time there is a task, there will always be a number of people together Qingzhan (numbers close to each other often in a piece, familiar with each other), eventually they get the military exploit, also would be divided into everyone, so, sometimes, It is a difficult thing to calculate which one of them is military exploit, the task of the Military Adviser is to ask a person's military exploit in the south when he has a quick report of his military exploit, please write a program to help the handyman.
Let's assume that everyone's military exploit at the start is 0.
-
-
Input
-
-
There is only one set of test data.
Each line is two integers t and M representing a total of T-bars, M soldiers. (1<=t,m<=1000000)
The subsequent T-line, each line is an instruction.
Directives are divided into two types:
A shape like
ADD 100 500 55 indicates that the 100th person to No. 500 person Qingzhan, eventually each person obtains the average 55 military exploit, each person obtains the military exploit number not to exceed 100, does not have less than 100.
The second form is as follows:
QUERY 300 indicates how much the South General is asking about the No. 300 person's military exploit.
Interval update, check Order # include <stdio.h> #include <string.h> #include <algorithm>using namespace Std;const int N = 1e6+5;struct tree{int l,r;int num;} t[n*4];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= (r+l)/2;build ( L,mid,2*root); build (mid+1,r,2*root+1);} void update (int l,int r,int val,int root) {if (l<=t[root].l&&t[root].r<=r) {T[root].num+=val;return;} int mid= (T[ROOT].L+T[ROOT].R)/2;if (r<=mid) update (l,r,val,2*root); else if (l>mid) update (L,R,VAL,2*ROOT+1); Else{update (l,mid,val,2*root); update (mid+1,r,val,2*root+1);}} int ans;void find (int id,int root) {ans+=t[root].num;if (T[ROOT].L==T[ROOT].R) {//ans=t[root].num;return;} int mid= (T[ROOT].L+T[ROOT].R)/2;if (id<=mid) find (Id,2*root); Elsefind (id,2*root+1);} int main () {int t,n;int X,y,z;char s[10];while (~scanf ("%d%d", &t,&n)) {build (1,n,1); while (t--) {scanf ("%s", s); if (s[0]== ' A ') {scanf ("%d%d%d", &x,&y,&z); update (x,y,z,1);} else if (s[0]== ' Q ') {scanf ("%d", &x); Ans=0;find (x,1);p rintf ("%d\n", ans);}} return 0;}