标签:打电话 other col mission void date inpu break sam
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 100935 Accepted Submission(s): 42687
#include<iostream>
using namespace std;
const int maxn=50002;
int tree[4*maxn];
void push_up(int i)
{
tree[i]=tree[i*2]+tree[i*2+1];
}
void build(int L,int R,int i)
{
if(L==R)
{
cin>>tree[i];
return ;
}
int mid=(L+R)/2;
build(L,mid,i*2);
build(mid+1,R,i*2+1);
push_up(i);
}
int query(int L,int R,int l,int r,int i)
{
if(L>=l&&R<=r)
return tree[i];
int mid=(L+R)/2;
int sum=0;
if(l<=mid)
sum+=query(L,mid,l,r,i*2);
if(r>mid)//else if 我觉得不行
sum+=query(mid+1,R,l,r,i*2+1);
return sum;
}
void update(int L,int R,int l,int val,int i)
{
if(L==R)
{
tree[i]+=val;
return ;
}
int mid=(L+R)/2;
if(l<=mid)
update(L,mid,l,val,i*2);
else
update(mid+1,R,l,val,i*2+1);
push_up(i);
}
int main()
{
ios::sync_with_stdio(false);//关闭流输入加速
int T;
cin>>T;//或者全部替换scanf("%d",&T);
int node=0;
while(T--)
{
int N;
cin>>N;
build(1,N,1);
cout<<"Case "<<++node<<":\n";
char a[7];
int x,y;
while(cin>>a)
{
if(a[0]==‘E‘)
break;
cin>>x>>y;
if(a[0]==‘Q‘)
cout<<query(1,N,x,y,1)<<endl;
else if(a[0]==‘A‘)
update(1,N,x,y,1);
else
update(1,N,x,-y,1);
}
}
return 0;
}
今天也是元气满满的一天!good!luck!
鸣谢Melo
标签:打电话 other col mission void date inpu break sam
原文地址:http://www.cnblogs.com/cattree/p/7628768.html