跳到正文

题解

题解:P11209 『STA - R8』小熊游景点 II

Daybreak_Firefly约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 2 分钟
获赞
1
题目
P11209

版本

  1. v1当前

简单的字典树。

思路为将符合条件的二进制数和二进制前缀存树里,然后快乐查询。

C++
//上次写太多字被多次打回qwq
#include<bits/stdc++.h>
using namespace std;
struct st{
	int to[2],cnt;
}edge[15000005];//01trie
int a[500005],b[500005];
int len;
void insert(int x,int y){
	int p=0;
	for (int i=31;i>=0;i--){
		int q=(x>>i)&1,w=(y>>i)&1;
		if (w){//这样才有小于机会
			if (!edge[p].to[q]) edge[p].to[q]=++len;//我老师4也不愿加个点 非得搞个二元组  q为q^w^1(w=1)
			edge[edge[p].to[q]].cnt++;//在这位小于就不用考虑下面
		}
		if (!edge[p].to[q^w]) edge[p].to[q^w]=++len;
		p=edge[p].to[q^w];//如果要使a^k=b则k=a^b
	}
	edge[p].cnt++;
	return ;
}
int answer(int x){
	int p=0,ans=0;
	for (int i=31;i>=0;i--){
		int c=(x>>i)&1;
		p=edge[p].to[c];
        if (p==0) break;
		ans+=edge[p].cnt;
	}
	return ans;
}//快乐查询
int main(){
	ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);//不加会TLE
	int t,n,m;
	cin>>t>>n>>m;
	for (int i=1;i<=n;i++) cin>>a[i];
	for (int i=1;i<=n;i++){
		cin>>b[i];
		insert(a[i],b[i]);
	}
	int ans=0;
	for (int i=1;i<=m;i++){
		int qwq;cin>>qwq;
		int k=qwq^(ans*t);
		ans=answer(k);
		cout<<ans<<'\n';
	}
	return 0;
}
原文