除了123 全过求调
查看原帖
除了123 全过求调
553501
可爱的小棉羊楼主2024/11/1 17:00
#include<bits/stdc++.h>
using namespace std;
int n,m,Ca[500005],Q[100005],lim,k,dep[500005],t[500005],pos[500005],p[25],opp[500005];
string str[25];
void build(int rt){
//	cout<<rt<<":\n";
	p[dep[rt]]++;
	if(dep[rt]==k){
//		cout<<"This is leafty "<<rt<<" "<<p[k]<<"\n";
		t[rt]=p[k];
		pos[p[k]]=rt;
		return;
	}
//	cout<<rt<<" "<<dep[rt]<<" "<<p[dep[rt]]-1<<" "<<(int)(str[dep[rt]][p[dep[rt]]-1])<<"\n";
	opp[rt]=str[dep[rt]][p[dep[rt]]-1]-'0';
	dep[rt<<1]=dep[rt<<1|1]=dep[rt]+1;
	build(rt<<1);
	build(rt<<1|1);
	return;
}
void init(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>Ca[i];
	for(int i=1;i<=m;i++)cin>>Q[i];
	lim=1,k=0;
	while(lim<=n){
		lim<<=1;
		k++; 
	}
	for(int i=k-1;i>=0;i--)cin>>str[i];
	//0--1
	build(1);
}
int a[200005],f[400005],g[400005];
long long ans[400005];
void dfs1(int rt){
//	cout<<rt<<":\n";
	if(dep[rt]==k){
//		cout<<"Leaf: "<<t[rt]<<"\n";
		f[rt]=t[rt];
		g[rt]=t[rt]-1;
		return;
	}
	dfs1(rt<<1),dfs1(rt<<1|1);
//	cout<<"g f of "<<rt<<" "<<opp[rt]<<"\n";
	
	
	if(!opp[rt]){
		if(a[f[rt<<1]]>=k-dep[rt]){
			f[rt]=f[rt<<1];
			g[rt]=g[rt<<1];
		}else{
			f[rt]=f[rt<<1|1];
			g[rt]=g[rt<<1|1];
		}
		g[rt]=max(g[rt],g[rt<<1]);
	}else{
		if(a[f[rt<<1|1]]>=k-dep[rt]){
			f[rt]=f[rt<<1|1];
			g[rt]=g[rt<<1|1];
		}else{
			f[rt]=f[rt<<1];
			g[rt]=g[rt<<1];
		}
		g[rt]=max(g[rt],g[rt<<1|1]);
	}
//	cout<<f[rt]<<" "<<g[rt]<<'\n';
	return ;
}
void add(int l,int r,int val){
	if(l>r)return;
	ans[l]+=val;
	ans[r+1]-=val;
}
void dfs2(int rt,int L,int R,int r,int mx){
	
	if(r<L)return;
//	cout<<rt<<":\n";
	if(dep[rt]==k){
		
		int p=t[rt];
//		cout<<p<<":\n"<<" "<<L<<" "<<R<<" "<<r<<" "<<mx<<"\n";
		if(p<=n&&a[p]>=mx){
//			cout<<"add "<<max(L,p)<<" "<<min(R,r)<<"\n";
			add(max(L,p),min(R,r),p);
		}
//		cout<<"add "<<L<<" "<<min(r,p-1)<<"\n";
		add(L,min(r,p-1),p);
		return;
	}
	if(!opp[rt]){
//		cout<<"by ls "<<r<<" "<<max(mx,k-dep[rt])<<"\n";
		dfs2(rt<<1,L,R,r,max(mx,k-dep[rt]));
//		cout<<"by rs "<<((a[f[rt<<1]]>=k-dep[rt])? min(r,g[rt<<1]):r)<<" "<<mx<<"\n";
		dfs2(rt<<1|1,L,R,(a[f[rt<<1]]>=k-dep[rt])? min(r,g[rt<<1]):r,mx);
	}else{
//		cout<<"by ls "<<((a[f[rt<<1|1]]>=k-dep[rt])? min(r,g[rt<<1|1]):r)<<" "<<mx<<"\n";
		dfs2(rt<<1,L,R,(a[f[rt<<1|1]]>=k-dep[rt])? min(r,g[rt<<1|1]):r,mx);
//		cout<<"by rs "<<r<<" "<<max(mx,k-dep[rt])<<"\n";
		dfs2(rt<<1|1,L,R,r,max(mx,k-dep[rt]));
		
	}
}
void work(){
	int X[5];
	cin>>X[0]>>X[1]>>X[2]>>X[3];
	for(int i=1;i<=lim;i++)ans[i]=0;
	for(int i=1;i<=n;i++)a[i]=Ca[i]^X[i%4];
//	for(int i=1;i<=n;i++)cout<<a[i]<<" ";
//	cout<<"\n";
	for(int i=n+1;i<=lim;i++)a[i]=0x3f3f3f3f;
	dfs1(1);
	add(1,1,1);
	int d=0,rt=1;
	while(rt<=(lim>>1)){
//		cout<<rt<<" "<<d<<" is my Q subtree\n"<<" "<<((1<<(k-d-1))+1)<<" "<<(1<<(k-d))<<"\n";
		//0
		dfs2(rt,(1<<(k-d-1))+1,1<<(k-d),0x3f3f3f3f,0);
		rt<<=1;
		d++;
	}
	long long sum=0;
	for(int i=1;i<=n;i++)ans[i]+=ans[i-1];
//	for(int i=1;i<=n;i++)cout<<ans[i]<<" ";
//	cout<<'\n';
	for(int i=1;i<=m;i++)sum^=i*ans[Q[i]];
	cout<<sum<<"\n";
}
int main(){
//	freopen("arena5.in","r",stdin);
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	init();
	int T;
	cin>>T;
	while(T--){
		work();
	}
	return 0;
}
/*
5 5
0 0 0 0 0
5 4 1 2 3
1001
10
1
1
2 1 0 0
*/

2024/11/1 17:00
加载中...