题意:

传送门

给\(n\)个集合,每个集合有一些数。给出\(m\)个询问,再给出\(l\)和\(r\)和一个数\(v\),问你任意的\(i \in[l,r]\)的集合,能不能找出子集异或为\(v\)。简单点说,\(v\)能用\([l,r]\)任意一个集合的子集异或和表示。

思路:

子集异或和显然是用线性基。我们用线段树维护任意区间的线性基交集即可。

代码:

/**
求交集 O(logn * logn)
**/
LBasis intersection(const LBasis &a, const LBasis &b){LBasis ans, c = b, d = b;ans.init();for (int i = 0; i <= 32; i++){ll x = a.d[i];if(!x)continue;int j = i;ll T = 0;for(; j >= 0; --j){if((x >> j) & 1)if(c.d[j]) {x ^= c.d[j]; T ^= d.d[j];}else break;}if(!x) ans.d[i] = T;else {c.d[j] = x; d.d[j] = T;}}return ans;
}
#include<map>
#include<set>
#include<cmath>
#include<cstdio>
#include<stack>
#include<ctime>
#include<vector>
#include<queue>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<algorithm>
typedef long long ll;
using namespace std;
const int maxn = 50000 + 5;
const int INF = 0x3f3f3f3f;
const ll MOD = 1e9 + 7;
using namespace std;struct LBasis{ll d[33];int tot;void init(){memset(d, 0, sizeof(d));tot = 0;}bool insert(ll x){for(int i = 32; i >= 0; i--){if(x & (1LL << i)){if(d[i]) x ^= d[i];else{d[i] = x;return true;}}}return false;}bool checkin(ll x){for(int i = 32; i >= 0; i--){if(x & (1LL << i)){if(d[i]) x ^= d[i];else return false;}}return true;}};
LBasis intersection(const LBasis &a, const LBasis &b){LBasis ans, c = b, d = b;ans.init();for (int i = 0; i <= 32; i++){ll x = a.d[i];if(!x)continue;int j = i;ll T = 0;for(; j >= 0; --j){if((x >> j) & 1)if(c.d[j]) {x ^= c.d[j]; T ^= d.d[j];}else break;}if(!x) ans.d[i] = T;else {c.d[j] = x; d.d[j] = T;}}return ans;
}
LBasis node[maxn << 2];
void pushup(int rt){node[rt] = intersection(node[rt << 1], node[rt << 1 | 1]);
}
void build(int l, int r, int rt){if(l == r){int sz;scanf("%d", &sz);node[rt].init();while(sz--){ll x;scanf("%lld", &x);node[rt].insert(x);}return;}int m = (l + r) >> 1;build(l, m, rt << 1);build(m + 1, r, rt << 1 | 1);pushup(rt);
}
bool query(int L, int R, int l, int r, ll v, int rt){if(L <= l && R >= r){return node[rt].checkin(v);}int m = (l + r) >> 1;bool ok = true;if(L <= m)ok = ok && query(L, R, l, m, v, rt << 1);if(R > m)ok = ok && query(L, R, m + 1, r, v, rt << 1 | 1);return ok;
}
int main(){int n, m;scanf("%d%d", &n, &m);build(1, n, 1);while(m--){int l, r;ll x;scanf("%d%d%lld", &l, &r, &x);if(query(l, r, 1, n, x, 1)) printf("YES\n");else printf("NO\n");}return 0;
}

转载于:https://www.cnblogs.com/KirinSB/p/11289022.html

2019牛客多校第四场B xor(线性基求交)题解相关推荐

  1. 2019牛客多校第四场 B xor (线性基求交)

    xor 思路 题目是要求[l,r][l, r][l,r]的所有集合是否都可以得到xxx,那么显然我们可以对这[l,r][l, r][l,r]个线性基求交,然后再特判能否xxx能否插入,如果能插入,显然 ...

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

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

  3. 牛客多校第四场【B-Basic Gcd Problem】

    牛客多校第四场[B-Basic Gcd Problem] 题目链接:https://ac.nowcoder.com/acm/contest/5669/B 思路:先要理解公式,多看几个数据基本就会有点想 ...

  4. 2019牛客多校训练营第一场 H题 HOR 题解

    题目描述: 输入描述: 输出描述: 示例1: 题解: 更多问题可关注牛客竞赛区,一个刷题.比赛.分享的社区. 传送门:https://ac.nowcoder.com/acm/contest/discu ...

  5. 2019牛客多校 第七场 B Irreducible Polynomial 多项式因式分解判断

    链接:https://ac.nowcoder.com/acm/contest/887/B 来源:牛客网 Irreducible Polynomial 时间限制:C/C++ 1秒,其他语言2秒 空间限制 ...

  6. 2019牛客多校训练营第一场 E题 ABBA 题解

    问题描述: 输入描述: 输出描述: 示例1: 题解: 更多问题可关注牛客竞赛区,一个刷题.比赛.分享的社区. 传送门:https://ac.nowcoder.com/acm/contest/discu ...

  7. 2019牛客多校第七场 C Governing sand

    因为当时时间不怎么够就没写... 其实就是一个模拟题而已下面注释很清楚 链接:https://ac.nowcoder.com/acm/contest/887/C 来源:牛客网 时间限制:C/C++ 3 ...

  8. [题解]Shorten IPv6 Address-模拟(2019牛客多校第六场B题)

    题目链接:https://ac.nowcoder.com/acm/contest/886/B 题意: 您将获得一个IPv6地址,该地址是128位二进制字符串.请根据以下规则确定其最短的表示: 以十六进 ...

  9. 2022 年牛客多校第四场补题记录

    A Task Computing 题意:给定长度为 nnn 的序列 {(wi,pi)}\{(w_i,p_i)\}{(wi​,pi​)},从中选出 mmm 项并重新排列得到子序列 {a1,a2,⋯,am ...

  10. 2019牛客多校第六场 E Androgynos

    传送门:https://ac.nowcoder.com/acm/contest/886/E 首先要同构的话,必须补图和原图边数一样,完全图总边数就必须是偶数,那么只有n%4=1 和 n%4=0时总边数 ...

最新文章

  1. ESXi6.5环境搭建(三:vSphere Client6.0安装)
  2. 启动Mysql时发生的一个关于PID文件错误问题
  3. 八十三、Eureka实现相互注册
  4. JavaScript算法(实例一)完数 / 水仙花数 / 素数
  5. redhat 6.4 mysql_redhat6.4 安装 MySQL 5.6.27
  6. 玩转 SpringBoot 2 快速整合 Filter 注解版
  7. mupdf嵌入 html页面,MuPDF Command Line Tools
  8. SQL server 2012 数据库还原操作
  9. elasticsearch中文分词
  10. 功能性模块:(7)检测性能评估模块(precision,recall等)
  11. 信用评分卡DAY8-9
  12. 完美的word转pdf
  13. 申诉解决TeamViewer免费个人版被误判为商业使用
  14. 5G NR 随机接入RACH流程(3)-- Msg1之选择正确的PRACH时频资源
  15. oppo A3怎么刷机 oppo A3的刷机教程 oppo A3完美解除账号锁
  16. HTML静态网页作业——电影介绍-你的名字 5页 无js 带音乐
  17. 多路选择器,加法器原理及verilog实现
  18. 【扔掉计算器】数学心算法《超棒超快》
  19. 计算机办公应用实训教程,《21世纪高等学校规划教材·计算机应用:Office办公软件同步实训教程》—甲虎网一站式图书批发平台...
  20. android9.0系统下,如何保活

热门文章

  1. 在 Linux 上如何清除内存的 Cache、Buffer 和交换空间
  2. 《数据结构与算法 C语言版》—— 2.2线性表的顺序表示与实现
  3. Android之HandlerThread
  4. [Visual Studio] 重置默认设置 还原默认设置
  5. 一个真实的实例: Java程序员的成长经历
  6. 春节见闻之北京前门步行街
  7. ISA发布邮件服务器
  8. JAVA HttpURLConnection 获取网页内容
  9. 干掉if-else,试试状态模式!
  10. 全员远程办公,半年入 1 亿美元:GitHub 的最大竞争对手上市了