求助85WAqwq
查看原帖
求助85WAqwq
665772
Haoyue_06432楼主2023/10/18 19:24
#include<bits/stdc++.h>
#define ll long long
#define maxn 4000040
#define inf 1e18
using namespace std;
ll n,m,q,opt,x,y,ans[maxn],d0[maxn],d1[maxn],mm,k,sum,num,e0,e1,e2;
char a[maxn][55],b[55];
bool bj[maxn];
void build(ll l,ll r,ll s)
{
	if(l==r)
	{
		for(int i=0;i<m;i++)
		{
			if(a[l][i]=='0')d0[s]+=1<<i;
			if(a[l][i]=='1')d1[s]+=1<<i;
		}
		return;
	}
	build(l,(l+r)/2,s*2);
	build((l+r)/2+1,r,s*2+1);
	bj[s]=(bj[s*2]|bj[s*2+1]);
	if(!bj[s])
	{
		ll x=d0[s*2]|d0[s*2+1],y=d1[s*2]|d1[s*2+1],z=(mm-d0[s*2]-d1[s*2])&(mm-d0[s*2+1]-d1[s*2+1]);
		if(x+y+z!=mm)bj[s]=true;
		d0[s]=x;d1[s]=y;
	}
}
void update(ll x,char z[],ll l,ll r,ll s)
{
	if(l>x||r<x)return;
	d0[s]=0;d1[s]=0;bj[s]=false;
	if(l==r&&l==x)
	{
		for(int i=0;i<m;i++)
		{
			if(z[i]=='0')d0[s]+=1<<i;
			if(z[i]=='1')d1[s]+=1<<i;
		}
		return;
	}
	update(x,z,l,(l+r)/2,s*2);
	update(x,z,(l+r)/2+1,r,s*2+1);
	bj[s]=(bj[s*2]|bj[s*2+1]);
	if(!bj[s])
	{
		ll x=d0[s*2]|d0[s*2+1],y=d1[s*2]|d1[s*2+1],z=(mm-d0[s*2]-d1[s*2])&(mm-d0[s*2+1]-d1[s*2+1]);
		if(x+y+z!=mm)bj[s]=true;
		d0[s]=x;d1[s]=y;
	}
}
bool find(ll x,ll y,ll l,ll r,ll s)
{
	if(l>y||r<x)return false;
	if(x<=l&&r<=y)
	{
		e0=e0|d0[s];e1=e1|d1[s];
		if(e2)e2=e2&(mm-d0[s]-d1[s]);
		else e2=mm-d0[s]-d1[s];
		if(e0+e1+e2!=mm)return true|bj[s];
		else return false|bj[s];
	}
	return (find(x,y,l,(l+r)/2,s*2)|find(x,y,(l+r)/2+1,r,s*2+1));
}
int main()
{
	scanf("%lld%lld%lld",&m,&n,&q);mm=(1<<m)-1;
	for(int i=1;i<=n;i++)scanf("%s",a[i]);
	build(1,n,1);
	for(int i=1;i<=q;i++)
	{
//		for(int j=1;j<=n*2;j++)cout<<d0[j]<<" "<<d1[j]<<" "<<bj[j]<<endl;cout<<endl;
		scanf("%lld%lld",&opt,&x);
		if(opt==0)
		{
			scanf("%lld",&y);		
			num=0;k++;e0=0;e1=0;e2=0;
//			cout<<find(x,y,1,n,1)<<endl;
			if(!find(x,y,1,n,1))
			{
				while(e2)
				{
					if(e2%2==1)num++;
					e2>>=1;
				}
				ans[k]=1<<num;
//				cout<<ans[k]<<endl;
			}
		}
		if(opt==1)
		{
			scanf("%s",b);
			update(x,b,1,n,1);
		}
	}
	for(int i=1;i<=k;i++)sum=(sum^ans[i]);
	printf("%lld",sum);
	return 0;
}
/*
3 3 1000
010
0?0
1?0
1 3 0??
*/
2023/10/18 19:24
加载中...