标签:int ret char 程序 -- 汇报 scan 开始 mit
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1166
敌兵布阵
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 86679 Accepted Submission(s): 36535
1 #include<stdio.h> 2 #include<string.h> 3 int a[50000],t[4*50000]; 4 void bulid(int p,int z,int y) //建树 5 { 6 if(z==y) 7 { 8 t[p]=a[z]; 9 return ; 10 } 11 int mid=(z+y)>>1; 12 bulid(p*2,z,mid); 13 bulid(p*2+1,mid+1,y); 14 t[p]=t[p*2]+t[p*2+1]; 15 } 16 void ADD(int p,int z,int y,int a,int b) 17 { 18 if(z==y) 19 { 20 t[p]+=b; 21 return ; 22 } 23 int mid=(z+y)>>1; 24 if(a<=mid) 25 ADD(p*2,z,mid,a,b); 26 else ADD(p*2+1,mid+1,y,a,b); 27 t[p]=t[p*2]+t[p*2+1]; 28 29 } 30 int QQ(int p,int z,int y,int a,int b) 31 { 32 int A; 33 if(a<=z&&y<=b) 34 { 35 return t[p]; 36 } 37 int mid=(z+y)>>1; 38 if(b<=mid) 39 return QQ(p*2,z,mid,a,b); 40 if(a>mid) 41 return QQ(p*2+1,mid+1,y,a,b); 42 return QQ(p*2,z,mid,a,mid)+QQ(p*2+1,mid+1,y,mid+1,b); 43 } 44 int main() 45 { 46 int tt,n,i,j,kk,x,y; 47 char aa[10]; 48 scanf("%d",&tt); 49 kk=1; 50 while(tt--) 51 { 52 scanf("%d",&n); 53 memset(a,0,sizeof(a)); 54 memset(t,0,sizeof(t)); 55 for(i=1;i<=n;i++) 56 scanf("%d",&a[i]); 57 bulid(1,1,n); 58 printf("Case %d:\n",kk++); 59 while(scanf("%s",aa)!=EOF) 60 { 61 if(aa[0]==‘E‘) 62 break; 63 scanf("%d%d",&x,&y); 64 if(aa[0]==‘A‘) ADD(1,1,n,x,y); 65 if(aa[0]==‘S‘) ADD(1,1,n,x,-y); 66 if(aa[0]==‘Q‘) printf("%d\n",QQ(1,1,n,x,y)); 67 } 68 } 69 return 0; 70 }
标签:int ret char 程序 -- 汇报 scan 开始 mit
原文地址:http://www.cnblogs.com/ljmzzyk/p/6708345.html