[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 ...
随机推荐
- springAOP基于注解的使用方法和实现原理
springAOP即面向切面编程,可以在方法执行过程中动态的织入增强逻辑,其使用步骤为: 1. 导入aop模块的jar包,或在maven中添加依赖:spring-aspects 2. 定义目标类和目 ...
- Java 实现Excel的简单读取操作
JAVA实现Excel表单的简单读取操作 实现Excel表单的简单读取操作,首先要导入相关的jar包: 如图所示: 此处贴上代码: public static List<List<Stri ...
- c# 对象相等性和同一性
一:对象相等性和同一性 System.Object提供了名为Equals的虚方法,作用是在两个对象包含相同值的前提下返回true,内部实现 public class Object { public v ...
- C语言如何操作内存
1.用变量名来访问内存(c语言对内存地址的封装.数据类型.函数名)--直接访问内存(使用地址) 如 int a; 编译器将申请32bit的内存(4个内存单元),同时将内存地址和变量名a绑定,操作a时, ...
- SQL Puzzle
1. 按条件分块取数据 有表A(CD),数据为 要求:当有CD为0的记录时,取得结果为0, 当表中没有CD=0的记录时,取得的结果为1,2,3(将CD<>0的记录都取出来) 可行SQL脚本 ...
- SpringBoot 使用logback
1.添加pom引用 <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback ...
- mysql续集(查询部分)
mysql查询部分,从基础的查询到关键字,where子句,group by, order by, limit ,having,子查询分为from子查询和where子查询,左连接和右连接,内连接的连表查 ...
- 一个阿里云apache服务器配置两个或多个域名forLinux
一个阿里云apache服务器配置两个或多个域名for Linux: 默认已经配置好了阿里云提供的一键web安装,可以参考:http://www.42iot.com/?id=8 修改/alidata/s ...
- Java使用POI读取和写入Excel指南(转)
做项目时经常有通过程序读取Excel数据,或是创建新的Excel并写入数据的需求: 网上很多经验教程里使用的POI版本都比较老了,一些API在新版里已经废弃,这里基于最新的Apache POI 4.0 ...
- MVC调用函数function.php
<?php //控制器的调用函数C function C($name, $method){ require_once('/libs/controller/'.$name.'Controller. ...