[CF959F]Mahmoud and Ehab and yet another xor task题解
搞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题解的更多相关文章
- Codeforces 959F Mahmoud and Ehab and yet another xor task 线性基 (看题解)
Mahmoud and Ehab and yet another xor task 存在的元素的方案数都是一样的, 啊, 我好菜啊. 离线之后用线性基取check存不存在,然后计算答案. #inclu ...
- Codeforces 959 F. Mahmoud and Ehab and yet another xor task
\(>Codeforces\space959 F. Mahmoud\ and\ Ehab\ and\ yet\ another\ xor\ task<\) 题目大意 : 给出一个长度为 \ ...
- 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的子序列 ...
- [CF959D]Mahmoud and Ehab and another array construction task题解
解法 非常暴力的模拟. 一开始吧\(1 -> 2 \times 10^6\)全部扔进一个set里,如果之前取得数都是与原数组相同的,那么lower_bound一下找到set中大于等于它的数,否则 ...
- codeforces-473D Mahmoud and Ehab and another array construction task (素数筛法+贪心)
题目传送门 题目大意:先提供一个数组,让你造一个数组,这个数组的要求是 1 各元素之间都互质 2 字典序大于等于原数组 3 每一个元素都大于2 思路: 1.两个数互质的意思就是没有公因子.所以每 ...
- Codeforces 959D. Mahmoud and Ehab and another array construction task(构造, 简单数论)
Codeforces 959D. Mahmoud and Ehab and another array construction task 题意 构造一个任意两个数都互质的序列,使其字典序大等于a序列 ...
- D. Mahmoud and Ehab and another array construction task 因子分界模板+贪心+数学
D. Mahmoud and Ehab and another array construction task 因子分解模板 题意 给出一个原序列a 找出一个字典序大于a的序列b,使得任意 \(i!= ...
- 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 ...
- 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 ...
随机推荐
- Apache solr 6.6.0安装
Apache solr 6.6.0安装 最近使用了Apache solr搜索引擎框架,solr是基于lucene的一个搜索服务器,lucene也是Apache的一个开源项目:对于学习搜索引擎来说,这个 ...
- 循环结构 :do-while
循环结构 :do-while 循环四要素: 1.初始化条件 2.循环条件 3.循环体 4.迭代条件 格式: 1.初始化条件 do{ 3.循环体 4.迭代条件 }while(2.循环条件); publi ...
- [BZOJ 3173] [TJOI 2013] 最长上升子序列(fhq treap)
[BZOJ 3173] [TJOI 2013] 最长上升子序列(fhq treap) 题面 给定一个序列,初始为空.现在我们将1到N的数字插入到序列中,每次将一个数字插入到一个特定的位置.每插入一个数 ...
- VBA中Let与Set的区别
Let与Set的区别 1.在“类模块”中 Property Let 语句 在Class块中,是给普通变量进行赋值操作的Property,该种Property将不能在其前面使用Set,因而将不能用户对对 ...
- TCP/IP详解学习笔记(3)IP协议ARP协议和RARP协议
把这三个协议放到一起学习是因为这三个协议处于同一层,ARP协议用来找到目标主机的Ethernet网卡Mac地址,IP则承载要发送的消息.数据链路层可以从ARP得到数据的传送信息,而从IP得到要传输的数 ...
- Ubuntu Anaconda3 环境下安装caffe
安装Python环境 本人环境为Anaconda3 ,可参照 https://blog.csdn.net/ctwy291314/article/details/86571198 完成安装Python2 ...
- Python + logging输出到屏幕,将log日志写入到文件
logging提供了一组便利的函数,用来做简单的日志.它们是 debug(). info(). warning(). error() 和 critical(). logging函数根据它们用来跟踪的事 ...
- Tree命令安装和使用
Tree命令简介 tree是一种递归目录列表命令,产生一个深度缩进列表文件,这是彩色的ALA dircolors如果ls_colors设置环境变量和输出是TTY.树已经被移植和报道以下操作系统下工作: ...
- 13Ajax和JQuery
1.Ajax 1.1是什么? “Asynchronous Javascript And XML”(异步JavaScript和XML), 并不是新的技术,只是把原有的技术,整合到一起而已. 1.使用CS ...
- UVAlive 3485 Bridge(抛物线弧长积分)
Bridge A suspension bridge suspends the roadway from huge main cables, which extend from one end of ...