题目
题目链接:https://vjudge.net/contest/357681#problem/U
代码
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<ctime>
#include<iostream>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<iomanip>
#include<list>
#include<bitset>
#include<sstream>
#include<fstream>
#include<complex>
#include<algorithm>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define ll long long
#define int long long
using namespace std;
const int INF = 0x3f3f3f3f;
inline int lowbit(int x) {return (-x)&x;}
int bit[505010];
int n,m;
void edit(int pos,int val){
for(int i=pos;i<=n;i+=lowbit(i)){
bit[i]+=val;
}
}
int query(int pos){
int res=0;
for(int i=pos;i>=1;i-=lowbit(i)){
res+=bit[i];
}
return res;
}
signed main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
scanf("%lld%lld",&n,&m);
while(m--){
char c;
getchar();//*****不要忘了!!!!!!!!
scanf("%c",&c);
if(c=='A'){
int b;
scanf("%lld",&b);
printf("%lld\n",query(b));
}
if(c=='B'){
int b,c1;
scanf("%lld%lld",&b,&c1);
edit(b,c1);
}
if(c=='C'){
int b,c1;
scanf("%lld%lld",&b,&c1);
edit(b,-c1);
}
}
return 0;
}