蒟蒻树状数组求调,谢大佬
查看原帖
蒟蒻树状数组求调,谢大佬
251775
galiyuebing楼主2023/3/2 09:18
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <map>
using namespace std;
bool C[500100];
int n,m,op,x,y;
int lowbit(int k)
{
	return k&(-k);
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;++i)
	{
		scanf("%d",&op);
		if(op==1)
		{
			scanf("%d%d",&x,&y);
			int j,s=x+1;
			for(j=y;j>=x;j-=lowbit(j))
			{
				C[j]=!C[j];
				if(j-lowbit(j)<x)
				{
					s=j-lowbit(j)+1;
					break;
				}
			}
			for(int j=s;j<x;j+=lowbit(j))C[j]=!C[j];
		}
		else
		{
			scanf("%d",&x);
			bool b=false;
			for(int j=x;j<=n;j+=lowbit(j))
			{
				if(C[j])b=!b;
			}
			if(b)printf("1\n");
			else printf("0\n");
		}
	}
	return 0;
}



2023/3/2 09:18
加载中...