题解:CF959F Mahmoud and Ehab and yet another xor task
oi_tuanzhang · · 题解
CF959F Mahmoud and Ehab and yet another xor task
默认读者已学习过线性基
记目前操作到了
记 无伤大雅。为什么构成集合中可能出现
综上来看,异或和
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
using namespace std;
const int Maxn=1e5+5;
const int Mod=1e9+7;
int n,q,cnt,a[Maxn],lb[40],f[Maxn],ans[Maxn];
vector<pii> e[Maxn];
void insert(int x)
{
for(int i=31;i>=0;i--)
{
if(x>>i&1)
{
if(!lb[i])
{
lb[i]=x;
cnt++;
return ;
}
x=(lb[i]^x);
}
}
}
bool check(int x)
{
for(int i=31;i>=0;i--)
{
if(x>>i&1) x=(x^lb[i]);
}
return x==0;
}
signed main()
{
cin>>n>>q;
f[0]=1;
for(int i=1;i<=n;i++) f[i]=f[i-1]*2%Mod;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=q;i++)
{
int l,x;cin>>l>>x;
e[l].push_back({x,i});
}
for(int i=1;i<=n;i++)
{
insert(a[i]);
for(auto p:e[i])
{
int x=p.first,id=p.second;
if(check(x)) ans[id]=f[i-cnt];
}
}
for(int i=1;i<=q;i++) cout<<ans[i]<<'\n';
return 0;
}