#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+10;
int c[maxn];
int n,k;
int lowbit(int x)
{
return x&-x;
}
void updata(int x,int y)
{
while(x<=n)
{
c[x]+=y;
x+=lowbit(x);
}
}
int ask(int x)
{
int ans=0;
while(x)
{
ans+=c[x];
x-=lowbit(x);
}
return ans;
}
int main()
{
ios::sync_with_stdio(false);
cin>>n>>k;
for(int i=1;i<=k;i++)
{
char flag;
cin>>flag;
if(flag=='A')
{
int m;
cin>>m;
cout<<ask(m)<<endl;
}else if(flag=='B')
{
int m,p;
cin>>m>>p;
updata(m,p);
}else
{
int m,p;
cin>>m>>p;
updata(m,-p);
}
}
return 0;
}
线段树与树状数组
最新推荐文章于 2023-12-02 00:02:37 发布