标签:amp mes 多点 汇报 掌握 cin its put bit
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 113159 Accepted Submission(s): 47413
Sample Output
裸题
AC代码
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const ll mod=1000000007,maxn=5e4+50; 5 int sum[maxn<<2]; 6 int a[maxn],n; 7 void PushUP(int rt) 8 { 9 sum[rt]=sum[rt<<1]+sum[rt<<1|1]; 10 } 11 void Build(int l,int r,int rt) 12 { 13 if(l==r) 14 { 15 sum[rt]=a[l]; 16 return; 17 18 } 19 int m=(l+r)>>1; 20 Build(l,m,rt<<1); 21 Build(m+1,r,rt<<1|1); 22 PushUP(rt); 23 } 24 void Update(int L,int C,int l,int r,int rt) 25 { 26 if(l==r) 27 { 28 sum[rt]+=C; 29 return; 30 } 31 int m=(l+r)>>1; 32 if(L<=m) 33 Update(L,C,l,m,rt<<1); 34 else 35 Update(L,C,m+1,r,rt<<1|1); 36 PushUP(rt); 37 } 38 int Query(int L,int R,int l,int r,int rt) 39 { 40 if(L<=l&&r<=R) 41 { 42 return sum[rt]; 43 } 44 int m=(l+r)>>1; 45 int ans=0; 46 if(L<=m) 47 ans+=Query(L,R,l,m,rt<<1); 48 if(R>m) 49 ans+=Query(L,R,m+1,r,rt<<1|1); 50 return ans; 51 } 52 int main() 53 { 54 int t; 55 scanf("%d",&t); 56 int kase=1; 57 while(t--) 58 { 59 memset(sum,0,sizeof(sum)); 60 memset(a,0,sizeof(a)); 61 scanf("%d",&n); 62 for(int i=1; i<=n; i++) 63 { 64 scanf("%d",&a[i]); 65 } 66 Build(1,n,1); 67 printf("Case %d:\n",kase++); 68 while(1) 69 { 70 string s; 71 ll x,y; 72 cin>>s; 73 if(s=="End") 74 break; 75 scanf("%d %d",&x,&y); 76 if(s=="Query") 77 printf("%d\n",Query(x,y,1,n,1)); 78 else if(s=="Add") 79 Update(x,y,1,n,1); 80 else if(s=="Sub") 81 Update(x,-y,1,n,1); 82 } 83 } 84 }
标签:amp mes 多点 汇报 掌握 cin its put bit
原文地址:https://www.cnblogs.com/stranger-/p/9069442.html