#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int POT[200005],tree[524300],record[524300];
void initialize(int begin,int end,int node)
{
if(begin==end){tree[node]=POT[begin];record[begin]=node;}
else { int mid=(begin+end)/2;
initialize(begin,mid,2*node);
initialize(mid+1,end,2*node+1);
tree[node]=tree[2*node]+tree[2*node+1];
}
}
long long int query(int i,int j,int begin,int end,int node)
{
int p1,p2;
if(end<i || j<begin)return 0;
if(i<=begin && end<=j)return tree[node];
else {int mid=(begin+end)/2;
p1=query(i,j,begin,mid,2*node);
p2=query(i,j,mid+1,end,2*node+1);
return p1+p2;
}
}
void update(int index,int val,int begin,int end,int node)
{
int n=record[index];
tree[n]=val;
n/=2;
while(n>0)
{
tree[n]=tree[2*n]+tree[2*n+1];
n/=2;
}
}
int main()
{
int pot,t=1;
bool blank=false;
while(scanf("%d",&pot)==1)
{if(!pot)break;
int i;
for(i=0;i<pot;i++)
scanf("%d",&POT[i]);
if(blank)printf("\n");
char command[5];
//getchar();
initialize(0,pot-1,1);
/* for(i=1;i<50;i++)
{
cout<<"NODE "<<i<<" i"<<tree[i]<<endl;
}*/
// cout<<"hoise"<<endl;
printf("Case %d:\n",t);
t++;
while(true)
{
scanf("%s",&command);
if(strcmp("END",command)==0)break;
else if(strcmp(command,"M")==0){int a,b;
scanf("%d%d",&a,&b);
if(a>b)swap(a,b);
printf("%d\n",query(a-1,b-1,0,pot-1,1));
//getchar();
}
else if(strcmp(command,"S")==0){int val,index;
scanf("%d%d",&index,&val);
update(index-1,val,0,pot-1,1);
}
//else if(command=="S")
}
if(blank==false)blank=true;
}
}
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন