Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<algorithm>
- #include<iostream>
- using namespace std;
- int sum[50005],a,b;
- string s;
- int lowbit(int x){
- return x&(-x);
- }
- void update(int x,int y,int n)
- {
- for(int i=x;i<=n;i+=lowbit(i)){
- sum[i]+=y;
- }
- }
- int getsum(int x){
- int ans=0;
- for(int i=x;i;i-=lowbit(i)){
- ans+=sum[i];
- }
- return ans;
- }
- int main(){
- int t,k=1;
- cin>>t;
- while(t--){
- cout<<"Case "<<k<<":"<<endl;
- memset(sum,0,sizeof(sum));
- int n;
- cin>>n;
- for(int i=1;i<=n;i++){
- cin>>a;
- update(i,a,n);
- }
- cin>>s;
- while(s!="End"){
- cin>>a>>b;
- if(s=="Add"){
- update(a,b,n);
- }else{
- if(s=="Sub"){
- update(a,-b,n);
- }else{
- cout<<getsum(b)-getsum(a-1)<<endl;
- }
- }
- cin>>s;
- }
- k++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement