线段树求调
查看原帖
线段树求调
1063615
Scez楼主2024/8/7 10:56
#include<bits/stdc++.h>
#define ll long long
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
int n,q;
int opt,l,r,x;
int t[1919810];
int ls(int p){return p<<1;}
int rs(int p){return p<<1|1;}
void update(int p,int l,int r,int L,int R)
{
	if(L<=l&&r<=R)
	{
		t[p]^=1;
		return;
	}
	int mid=(l+r)>>1;
	if(L<=mid)
	update(ls(p),l,mid,L,R);
	if(R>mid)
	update(rs(p),mid+1,r,L,R);
}
int main()
{
	cin>>n>>q;
	while(q--)
	{
		cin>>opt;
		if(opt==1)
		{
			cin>>l>>r;
			update(1,1,n,l,r);
			for(int i=1;i<=n;i++)
			cout<<t[i]<<" ";
			cout<<endl;
		}
		if(opt==2)
		{
			cin>>x;
			cout<<t[x]<<endl;
		}
	}
	
	return 0;
}


2024/8/7 10:56
加载中...