[线段树] *区间调整 单点询问* CQOI2006

题目

在这里插入图片描述

题目链接:https://vjudge.net/contest/357681#problem/V

思路

其实变1变0可以和%2产生联系。
要改变的话让sum+1就行了

代码

#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;
}
发布了66 篇原创文章 · 获赞 1 · 访问量 3884

猜你喜欢

转载自blog.csdn.net/kosf_/article/details/104436125