Codeforces 959 F Mahmoud and Ehab and yet another xor task

Discription

Ehab has an array a of n integers. He likes the bitwise-xor operation and he likes to bother Mahmoud so he came up with a problem. He gave Mahmoud q queries. In each of them, he gave Mahmoud 2 integers l and x, and asked him to find the number of subsequences of the first l elements of the array such that their bitwise-xor sum isx. Can you help Mahmoud answer the queries?

A subsequence can contain elements that are not neighboring.

Input

The first line contains integers n and q (1 ≤ n, q ≤ 105), the number of elements in the array and the number of queries.

The next line contains n integers a1a2..., an (0 ≤ ai < 220), the elements of the array.

The next q lines, each contains integers l and x (1 ≤ l ≤ n0 ≤ x < 220), representing the queries.

Output

For each query, output its answer modulo 109 + 7 in a newline.

Examples

Input
5 5
0 1 2 3 4
4 3
2 0
3 7
5 7
5 8
Output
4
2
0
4
0
Input
3 2
1 1 1
3 1
2 0
Output
4
2

Note

The bitwise-xor sum of the empty set is 0 and the bitwise-xor sum of a set containing one element is that element itself.

 

 

    这不是一个前缀线性基SB题吗2333

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int ha=1000000007;
const int maxn=100005;
int ci[maxn],n,m,a[maxn],R,N;
int B[maxn][22],lef[maxn],Q;
inline int add(int x,int y){ x+=y; return x>=ha?x-ha:x;}
inline void init(){ ci[0]=1; for(int i=1;i<=100000;i++) ci[i]=add(ci[i-1],ci[i-1]);}
inline void build(int x){
	memcpy(B[x],B[x-1],sizeof(B[x-1]));
	for(int i=20;i>=0;i--) if(a[x]&ci[i]){
		if(!B[x][i]){
			B[x][i]=a[x];
			break;
		}
		a[x]^=B[x][i];
	}
	lef[x]=lef[x-1]+(!a[x]);
}
inline int query(){
	for(int i=20;i>=0;i--) if(N&ci[i]) N^=B[R][i];
	return N?0:ci[lef[R]];
}
int main(){
	scanf("%d%d",&n,&Q),init();
	for(int i=1;i<=n;i++) scanf("%d",a+i),build(i);
	while(Q--){
		scanf("%d%d",&R,&N);
		printf("%d\n",query());
	}
	return 0;
}

  

转载于:https://www.cnblogs.com/JYYHH/p/8835129.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值