题目链接

传送门

题意

给你\(n\)个基底,求\([l,r]\)内的每个基底是否都能异或出\(x\)。

思路

线性基交板子题,但是一直没看懂咋求,先偷一份咖啡鸡板子写篇博客吧~

线性基交学习博客:传送门

代码实现如下

#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std; typedef unsigned int ui;
typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL; #define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("D://Code//in.txt","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0)
#define fuck(x) cout<<#x" = "<<x<<endl const double eps = 1e-8;
const int mod = 1000000007;
const int maxn = 50000 + 7;
const double pi = acos ( -1 );
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL; ui x, a[maxn][35];
int n, q, sz, l, r; struct base{
ui r[32];
ui f[32];
bool ins(ui x){
for (int i=31;i>=0;i--)
if (x>>i){
if (!r[i]) {r[i]=x;return 1;}
x^=r[i];
if (!x) return 0;
}
return 0;
}
void ins2(ui x){
ui tmp=x;
for (int i=31;i>=0;i--)
if (x>>i){
if (!r[i]) {f[i]=tmp;r[i]=x;return;}
x^=r[i]; tmp^=f[i];
if (!x) return;
}
return;
}
bool find(ui x){
for (int i=31;i>=0;i--)
if (x>>i){
if (!r[i]) return 0;
x^=r[i];
}
return x==0;
}
ui calc(ui x){
ui ret=0;
for (int i=31;i>=0;i--){
if (x>>i){
ret^=f[i];
x^=r[i];
}
}
return ret;
}
void print(){
for (int i=0;i<32;i++)cout<<r[i]<<' ';cout<<endl;
}
void clear(){
for (int i=0;i<32;i++) r[i]=f[i]=0;
}
}; struct node {
int l, r;
base val;
}segtree[maxn<<2]; void push_up(int rt) {
base tmp = segtree[lson].val;
base ans;
ans.clear();
for(int i = 31; i >= 0; --i) {
ui x = segtree[rson].val.r[i];
if(tmp.find(x)) {
ans.ins(x^tmp.calc(x));
} else tmp.ins2(x);
}
segtree[rt].val = ans;
} void build(int rt, int l, int r) {
segtree[rt].l = l, segtree[rt].r = r;
if(l == r) {
for(int i = 0; i <= 31; ++i) segtree[rt].val.ins(a[l][i]);
return;
}
int mid = (l + r) >> 1;
build(lson, l, mid);
build(rson, mid + 1, r);
push_up(rt);
} bool query(int rt, int l, int r, LL x) {
if(segtree[rt].l == l && segtree[rt].r == r) {
return segtree[rt].val.find(x);
}
int mid = (segtree[rt].l + segtree[rt].r) >> 1;
if(r <= mid) return query(lson, l, r, x);
else if(l > mid) return query(rson, l, r, x);
else {
return query(lson, l, mid, x) && query(rson, mid + 1, r, x);
}
} int main() {
#ifndef ONLINE_JUDGE
FIN;
#endif // ONLINE_JUDGE
scanf("%d%d", &n, &q);
for(int i = 1; i <= n; ++i) {
scanf("%d", &sz);
for(int j = 0; j < sz; ++j) scanf("%lld", &a[i][j]);
for(int j = sz; j <= 31; ++j) a[i][j] = 0;
}
build(1, 1, n);
while(q--) {
scanf("%d%d%lld", &l, &r, &x);
if(query(1, l, r, x)) printf("YES\n");
else printf("NO\n");
}
return 0;
}

2019年牛客多校第四场 B题xor(线段树+线性基交)的更多相关文章

  1. 牛客多校第四场sequence C (线段树+单调栈)

    牛客多校第四场sequence C (线段树+单调栈) 传送门:https://ac.nowcoder.com/acm/contest/884/C 题意: 求一个$\max {1 \leq l \le ...

  2. 2019牛客多校第四场C-sequence(单调栈+线段树)

    sequence 题目传送门 解题思路 用单调栈求出每个a[i]作为最小值的最大范围.对于每个a[i],我们都要乘以一个以a[i]为区间内最小值的对应的b的区间和s,如果a[i] > 0,则s要 ...

  3. Palindrome Mouse(2019年牛客多校第六场C题+回文树+树状数组)

    目录 题目链接 题意 思路 代码 题目链接 传送门 题意 问\(s\)串中所有本质不同的回文子串中有多少对回文子串满足\(a\)是\(b\)的子串. 思路 参考代码:传送门 本质不同的回文子串肯定是要 ...

  4. 2019牛客多校第四场 I题 后缀自动机_后缀数组_求两个串de公共子串的种类数

    目录 求若干个串的公共子串个数相关变形题 对一个串建后缀自动机,另一个串在上面跑同时计数 广义后缀自动机 后缀数组 其他:POJ 3415 求两个串长度至少为k的公共子串数量 @(牛客多校第四场 I题 ...

  5. Distance(2019年牛客多校第八场D题+CDQ+树状数组)

    题目链接 传送门 思路 这个题在\(BZOJ\)上有个二维平面的版本(\(BZOJ2716\)天使玩偶),不过是权限题因此就不附带链接了,我也只是在算法进阶指南上看到过,那个题的写法是\(CDQ\), ...

  6. generator 1(2019年牛客多校第五场B题+十进制矩阵快速幂)

    目录 题目链接 思路 代码 题目链接 传送门 思路 十进制矩阵快速幂. 代码 #include <set> #include <map> #include <deque& ...

  7. Find the median(2019年牛客多校第七场E题+左闭右开线段树)

    题目链接 传送门 题意 每次往集合里面添加一段连续区间的数,然后询问当前集合内的中位数. 思路 思路很好想,但是卡内存. 当时写的动态开点线段树没卡过去,赛后机房大佬用动态开点过了,\(tql\). ...

  8. Explorer(2019年牛客多校第八场E题+线段树+可撤销并查集)

    题目链接 传送门 题意 给你一张无向图,每条边\(u_i,v_i\)的权值范围为\([L_i,R_i]\),要经过这条边的条件是你的容量要在\([L_i,R_i]\),现在问你你有多少种容量使得你可以 ...

  9. 2019年牛客多校第三场 F题Planting Trees(单调队列)

    题目链接 传送门 题意 给你一个\(n\times n\)的矩形,要你求出一个面积最大的矩形使得这个矩形内的最大值减最小值小于等于\(M\). 思路 单调队列滚动窗口. 比赛的时候我的想法是先枚举长度 ...

随机推荐

  1. 对post提交数据Content-Type的理解

    Content-Type是指http/https发送信息至服务器时的内容编码类型,contentType用于表明发送数据流的类型,服务器根据编码类型使用特定的解析方式,获取数据流中的数据. 在网络请求 ...

  2. java报错:The reference to entity "characterEncoding" must end with the ';' delimiter.

    java关于报错:The reference to entity "characterEncoding" must end with the ';' delimiter. Java ...

  3. 【Gamma】“北航社团帮”测试报告——小程序v3.0

    目录 测试计划.过程和结果 后端测试--单元测试与覆盖率 后端测试--压力测试 展示部分数据 平均数据 前端测试--小程序v3.0 新功能 各页面均可正常打开,跳转,回退 授权登录与权限检查 页面数据 ...

  4. Hyperledger Fabric 1.4 快速环境搭建

    自己的硕士研究方向和区块链有关,工程上一直以IBM的Hyperledger Fabric为基础进行开发,对该项目关注也有两年了.目前迎来了Hyperledger Fabric v1.4,这也是Fabr ...

  5. Java核心技术 卷一(序言+0-5)

    l 常见简写: JDK(Java Development Kit):Java开发工具包 API:应用程序编程接口 OOP(Object-Oriented Programming):面向对象程序设计 l ...

  6. standard_init_linux.go:178: exec user process caused "no such file or directory"

    golang docker build 制作完进项后运行报错 出现该问题的原因是编译的环境和运行的环境不同,可能有动态库的依赖 1.默认go使用静态链接,在docker的golang环境中默认是使用动 ...

  7. OpenGL学习 (一) - 简单窗口绘制

    一.OpenGL 简介 OpenGL 本质: OpenGL(Open Graphics Library),通常可以认为是API,其包含了一系列可以操作图形.图像的函数.但深究下来,它是由Khronos ...

  8. Linux学习笔记之安装报错/lib/ld-linux.so.2: bad ELF interpreter

    0x00 64位系统中安装了32位程序解决办法 是因为64位系统中安装了32位程序 解决方法: yum install glibc.i686 0x01 解决交叉编译环境错误 yum install l ...

  9. CMPP服务端源码

    CMPP服务端,带数据库,可以接收第三方CMPP客户端的短信,并存入数据库,结合我的cmpp客户端服务程序,将可以实现接收第三方SP的短信并转发到网关实现发送,并将状态报告.上行短信转发给第三方SP, ...

  10. Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile

    更换当前jdk版本为项目所需jdk版本即可