zoukankan      html  css  js  c++  java
  • 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
    ",query());
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    Linux开发环境必备十大开发工具
    mysql executemany与 insert ... ON DUPLICATE KEY UPDATE 一起使用
    python LD_LIBRARY_PATH 靠谱解决办法
    搭建简单ftp,满足windows和ubuntu共享文件
    用类方法作为装饰器装饰同属于本类的另一个方法
    通过类方法名调用类方法
    java将jpg文件转化为base64字节(互转)
    CSS元素居中的方式
    T-SQL语法学习一(持续更新)
    SVN的使用教程(一)
  • 原文地址:https://www.cnblogs.com/JYYHH/p/8835129.html
Copyright © 2011-2022 走看看