搞n个线性基,然后每次在上一次的基础上插入读入的数,前缀和线性基,或者说珂持久化线性基。

然后一个num数组记录当时线性基里有多少数

然后每次前缀操作一下就珂以了

代码

#include <cstdio>
#define ll long long const ll MOD = 1e9+7; ll read(){
ll x = 0; int zf = 1; char ch = ' ';
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') zf = -1, ch = getchar();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * zf;
} ll base[100005][25];
ll bit[100005];
int num[100005]; inline bool insert(int pos, ll x, int &num){
for (int i = 20; ~i; --i)
if (x & (1ll << i))
if (!base[pos][i]){
base[pos][i] = x;
++num;
break;
}
else
x ^= base[pos][i];
return (x > 0);
} inline ll judge(int pos, ll x){
for (int i = 20; ~i; --i){
if ((1ll << i) & x){
if (!base[pos][i])
return 0;
x ^= base[pos][i];
}
}
return (x == 0);
} int main(){
int n = read(), q = read();
bit[0] = 1;
for (int i = 1; i <= n; ++i)
bit[i] = (bit[i - 1] << 1ll) % MOD;
for (int i = 1; i <= n; ++i){
int x = read();
for (register int j = 20; ~j; --j) base[i][j] = base[i - 1][j];
num[i] = num[i - 1];
insert(i, x, num[i]);
}
for (int i = 0; i < q; ++i){
int l = read(), x = read();
if (!judge(l, x))
printf("0\n");
else
printf("%d\n", bit[l - num[l]]);
}
return 0;
}

[CF959F]Mahmoud and Ehab and yet another xor task题解的更多相关文章

  1. Codeforces 959F Mahmoud and Ehab and yet another xor task 线性基 (看题解)

    Mahmoud and Ehab and yet another xor task 存在的元素的方案数都是一样的, 啊, 我好菜啊. 离线之后用线性基取check存不存在,然后计算答案. #inclu ...

  2. Codeforces 959 F. Mahmoud and Ehab and yet another xor task

    \(>Codeforces\space959 F. Mahmoud\ and\ Ehab\ and\ yet\ another\ xor\ task<\) 题目大意 : 给出一个长度为 \ ...

  3. 959F - Mahmoud and Ehab and yet another xor task xor+dp(递推形)+离线

    959F - Mahmoud and Ehab and yet another xor task xor+dp+离线 题意 给出 n个值和q个询问,询问l,x,表示前l个数字子序列的异或和为x的子序列 ...

  4. [CF959D]Mahmoud and Ehab and another array construction task题解

    解法 非常暴力的模拟. 一开始吧\(1 -> 2 \times 10^6\)全部扔进一个set里,如果之前取得数都是与原数组相同的,那么lower_bound一下找到set中大于等于它的数,否则 ...

  5. codeforces-473D Mahmoud and Ehab and another array construction task (素数筛法+贪心)

    题目传送门 题目大意:先提供一个数组,让你造一个数组,这个数组的要求是 1 各元素之间都互质  2  字典序大于等于原数组  3 每一个元素都大于2 思路: 1.两个数互质的意思就是没有公因子.所以每 ...

  6. Codeforces 959D. Mahmoud and Ehab and another array construction task(构造, 简单数论)

    Codeforces 959D. Mahmoud and Ehab and another array construction task 题意 构造一个任意两个数都互质的序列,使其字典序大等于a序列 ...

  7. D. Mahmoud and Ehab and another array construction task 因子分界模板+贪心+数学

    D. Mahmoud and Ehab and another array construction task 因子分解模板 题意 给出一个原序列a 找出一个字典序大于a的序列b,使得任意 \(i!= ...

  8. CF959D Mahmoud and Ehab and another array construction task 数学

    Mahmoud has an array a consisting of n integers. He asked Ehab to find another array b of the same l ...

  9. Codeforces 959 D Mahmoud and Ehab and another array construction task

    Discription Mahmoud has an array a consisting of n integers. He asked Ehab to find another arrayb of ...

随机推荐

  1. 阶段1 语言基础+高级_1-3-Java语言高级_06-File类与IO流_04 IO字节流_12_练习_文件复制

    谁用字节可以读取任何文件. 读取后再写入到D盘去.这就是一个文件的复制. 怎么由C盘到D盘.这里要借助流技术 需要创建两个流,一个读取一个写入 图片复制过来了. 看一下图片的字节数.whilte循环要 ...

  2. Linux 服务器安全优化

    最小的权限+最少的服务=最大的安全 所以,无论是配置任何服务器,我们都必须把不用的服务关闭.把系统权限设置到最小,这样才能保证服务器最大的安全.下面是CentOS服务器安全设置,供大家参考. 一.注释 ...

  3. C#怎么让字符串定长,不够的用空格补齐

    string.PadLeft 或者 string.PadRight  : string.PadLeft 表示如果一个字符串的长度小于指定的值,则在字符串的左侧(也就是前面)用指定的字符填充,直到字符串 ...

  4. String类为什么是final

    String 本身一个对象,对象在jvm启动的时候就要实例化和其他类调用就要实例化,第一性能,第二安全,因为string的高频繁的使用,如果被继承,哪里性能将会大大降低,因为不能被继承,换句话来说就比 ...

  5. python基础-8迭代器(iter)和生成器(yield)

    一 生成器 从Python2.2起,生成器提供了一种简洁的方式帮助返回列表元素的函数来完成简单和有效的代码. 它基于yield指令,允许停止函数并立即返回结果.此函数保存其执行上下文,如果需要,可立即 ...

  6. 2019春第十一周作业Compile Summarize

    这个作业属于那个课程 C语言程序设计II 这个作业要求在哪里 这里 我在这个课程的目标是 能按自己的想法解出题目 这个作业在那个具体方面帮助我实现目标 能朝着软件工程师方向发展 参考文献与网址 C语言 ...

  7. 《剑指offer》面试题17 合并两个排序的链表 Java版

    我的方法:新初始化一个链表头,比较两个链表当前节点的大小,然后连接到该链表中.遍历两个链表直到null为止. public ListNode merge(ListNode first, ListNod ...

  8. 《剑指offer》面试题12 打印1到最大的n位数 Java版

    书中方法:这道题的一个陷阱在于不能用int或者long去存储你要打印的数,然后用打印函数打印,因为这个数可能会很大.如果加1后超出了最大的n位数,就不打印了.用最高位是否进位判断是否结束,打印的时候注 ...

  9. 封装和private,this,super关键字的简单应用

    1.将成员变量用private修饰 2.提供对应的getxx()和setxx()方法 public class Student { private String name; private int a ...

  10. ASE Alpha Sprint - backend scrum 9

    本次scrum于2019.11.14再sky garden进行,持续15分钟. 参与人: Xin Kang, Zhikai Chen, Jia Ning, Hao Wang 请假: Lihao Ran ...