P1889--Kitchen relief
Time limit: 1000MS
Memory Limit: 131072KB
Description
As we all know, Lzl owned n Kitchen, once was troubled by water pipe problem, in a certain God (Zhang) (GE) (GE) son (?) With the help of the plumbing exchanger, the kitchen finally worked normally. But Lzl recently met with new problems ...
Because the dish he made was so delicious (as his body), a lot of people are in batches to each kitchen to eat, which mainly have small z, small G, small c, small k and other people, which makes lzl very headache, because people are really too much, he can not quickly know how many kitchen or a kitchen there are a number of people, can not be in time to assign the chef to cope.
Now, Lzl found you and asked for help.
Input Format
Line 1th N, K stands for n Kitchens, K batches of people
The 2nd line has n numbers, indicating the number of people in each kitchen
From 3rd to k+2, each line has a q,a and B:
If q = 1, there is a and B, the kitchen labeled A is added to the B person (very strange, B is always greater than 0!). )
If q = 2, then there is a and B, which means you can output the total number of people in the kitchen (A, B)
Output Format
For each q=2 query, output the corresponding value
Sample Input
5 31 2 3 4 5 2 1 31 2 22 2 5
Sample Output
616
Hint
30% N <=, K <= 1000
50% N <=10000, K <= 10000
100% N <= 100000 K <= 100000
All the answers are within the Longlong range.
Zgg: Who is the mysterious man?
LZL: Ask CK, his question I don't know
Zgg: Lying trough, this is called the title? I finished 2 seconds.
LZL: ...
Exercises
Tree-like array bare topic
1#include <stdio.h>2 Charb[1<< the],*s=b,*t=B;3 #defineGetc () (s==t&& (t= (s=b) +fread (B,1,1<<15,stdin), s==t)? 0:*s++)4 intn,m,b[100001],c[100001],a[100001];5 intLowbit (intx) {returnx& (-x);}6 intGetint () {7 intx=0, f=1;CharCh=getc ();8 while(ch<'0'|| Ch>'9') {if(ch=='-') f=-1; Ch=getc ();}9 while(ch>='0'&&ch<='9') {x= (x<<3) + (x<<1) +ch-'0'; Ch=getc ();}Ten returnx*F; One } A voidModifyintXintDelta) { - - while(x<=N) { thec[x]+=Delta; -x+=lowbit (x); - } - } + intCalintx) { - intret=0; + while(x!=0) { Aret+=C[x]; atx-=lowbit (x); - } - returnret; - } - Main () { -N=getint (); m=getint (); in for(intI=1; i<=n;++i) { -b[i]=getint (); toa[i]=b[i]+a[i-1]; +c[i]=a[i]-a[i-lowbit (i)]; - } the while(m--) { * intxx=getint (); $ if(xx==2) {Panax Notoginseng intP,q;p=getint (); q=getint (); -printf"%d\n", Cal (q)-cal (P-1)); the } + if(xx==1) { A intP,q; P=getint (); q=getint (); the Modify (p,q); + } - } $}
View Code
[Fzyzoj 1889] Kitchen Relief