树状数组80分代码求调,错4,5,看上去没大问题
查看原帖
树状数组80分代码求调,错4,5,看上去没大问题
422348
Yang818楼主2023/10/8 17:35
#include<bits/stdc++.h>
#define F(_b,_e) for(int i=_b;i<=_e;i++)
#define int long long
using namespace std;

inline int read(){
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return f*x;
}
void write(int x) {
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+'0');
}
const int MAXN=1e5+50;
int t[MAXN],n,m;
int lowbit(int x){
	return x&-x;
} 
int query(int x){
	int sum=0;
	for(int i=x;i;i-=lowbit(i))
		sum+=t[i];
	return sum;
}
void modify(int x,int d){
	for(int i=x;i<n;i+=lowbit(i))
		t[i]+=d;
}
signed main(){
	//ios::sync_with_stdio(false);
	n=read();
	m=read();
	for(int i=1;i<=m;i++){
		int op=read();
		if(op==1){
			int t=read(),y=read();
			modify(t,1);
			modify(y+1,1);
		}
		else{
			int t=read();
			cout<<(query(t)&1)<<endl;
		}
	}
	return 0;
}

谢谢

2023/10/8 17:35
加载中...