跳到正文

题解

社论:CF959F Mahmoud and Ehab and yet another xor task

Jordan_Pan约 2 分钟
原文

这是 2026年9月20日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2026年9月20日
收录
2026年9月20日
更新
2026年11月11日
篇幅
约 2 分钟
获赞
1
题目
CF959F

版本

  1. v3当前
  2. v2
  3. v1

怎么没有人爆标?显然不需要线性基,不需要离线,不需要 O(nlog⁡V)O(n\log V)。

预处理从前往后扫,维护集合 SiS_i 为 a1,a2,⋯ ,aia_1,a_2,\cdots,a_i 可以异或出哪些数,ansi\text{ans}_i 为对于 x∈Six\in S_i 的答案,显然 ansi=2i−log⁡∣Si∣\text{ans}_i=2^{i-\log|S_i|}。

若 ai∈Si−1a_i\in S_{i-1},Si=Si−1S_i=S_{i-1} 不变;否则暴力翻倍扩张即可。

对于询问,维护每个数加入集合的时刻即可。

时间复杂度为 O(n+q+V)O(n+q+V),其中 V=220V=2^{20}。

INFO
C++
#include<bits/stdc++.h>
constexpr int rSiz=1<<21;
char rBuf[rSiz],*p1=rBuf,*p2=rBuf;
#define gc() (p1==p2&&(p2=(p1=rBuf)+fread(rBuf,1,rSiz,stdin),p1==p2)?EOF:*p1++)
template<class T>void rd(T&x){
	char ch=gc();
	for(;ch<'0'||ch>'9';ch=gc());
	for(x=0;ch>='0'&&ch<='9';ch=gc())
		x=(x<<1)+(x<<3)+(ch^48);
}
constexpr int _=1e5+5,__=1.1e6+5,mod=1e9+7;
int n,q,a[_],b[__];
std::basic_string<int>S,T;
bool vis[__];
int main(){
	rd(n),rd(q);
	memset(b,1,sizeof b);
	S+=0;vis[0]=a[0]=1;b[0]=0;
	for(int i=1,x;i<=n;++i){
		rd(x);a[i]=a[i-1];
		if(vis[x])a[i]=(a[i]<<1)%mod;
		else{
			T.clear();
			for(int y:S)T+=x^y;
			for(int v:T)S+=v,vis[v]=1,b[v]=i;
		}
	}
	for(int l,x;q;--q){
		rd(l),rd(x);
		if(b[x]<=l)printf("%d\n",a[l]);
		else printf("0\n");
	}
}