题意:

给你n个基,q个询问,每个询问问你能不能 l~r 的所有基都能表示 x 。

思路:

建一颗线性基的线段树,up就是求交的过程,按照线段树区间查询的方法进行check就可以了。

 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>
#include <bitset>
//#include <map>
//#include<unordered_map>
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr
#include <string>
#include <time.h>//srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
#include <vector>//emplace_back
//#include <math.h>
//#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
#define fo(a,b,c) for(register int a=b;a<=c;++a)
#define fr(a,b,c) for(register int a=b;a>=c;--a)
#define mem(a,b) memset(a,b,sizeof(a))
#define pr printf
#define sc scanf
void swapp(int &a,int &b);
double fabss(double a);
int maxx(int a,int b);
int minn(int a,int b);
int Del_bit_1(int n);
int lowbit(int n);
int abss(int a);
//const long long INF=(1LL<<60);
const double E=2.718281828;
const double PI=acos(-1.0);
const int inf=(<<);
const double ESP=1e-;
const int mod=(int)1e9+;
const int N=(int)1e6+; struct node
{
long long base[]; void Init()
{
for(int i=;i<;++i)
base[i]=;
} bool check(long long x)
{
for(int i=;i>=;--i)
{
if(x&(1LL<<i))
{
if(!base[i])return ;
else x^=base[i];
}
}
return ;
} void Insert(long long x)
{
for(int i=;i>=;--i)
{
if(x>>i&)
{
if(base[i])
x^=base[i];
else
{
base[i]=x;
break;
}
}
}
}
}BASE[N<<],temp,v; void merge(const node &a,node &b,node &ans)
{
temp=v=a;
fo(i,,)
{
if(b.base[i])
{
long long x=b.base[i],now=;
int g=;
for(int j=;j>=;j--)
{
if(x>>j&)
{
if(!temp.base[j])
{
g=;
temp.base[j]=x;
v.base[j]=now;
break;
}
x^=temp.base[j];now^=v.base[j];
}
}
if(!g)
ans.Insert(now);
}
}
} void up(int rt)
{
merge(BASE[rt<<],BASE[rt<<|],BASE[rt]);
}
void Build(int l,int r,int rt)
{
if(l==r)
{
int sz;
long long x;
sc("%d",&sz);
fo(i,,sz)
{
sc("%lld",&x);
BASE[rt].Insert(x);
}
return;
}
int mid=(l+r)>>; Build(l,mid,rt<<);
Build(mid+,r,rt<<|);
up(rt);
}
bool Query(int L,int R,long long V,int l,int r,int rt)
{
if(L<=l&&r<=R)
return BASE[rt].check(V);
int mid=(l+r)>>; if(L<=mid&&!Query(L,R,V,l,mid,rt<<))
return ;
if(R>mid&&!Query(L,R,V,mid+,r,rt<<|))
return ;
return ;
} int main()
{
int n,m;
sc("%d%d",&n,&m); Build(,n,);
fo(i,,m)
{
int l,r;
long long x;
sc("%d%d%lld",&l,&r,&x);
if(Query(l,r,x,,n,))
pr("YES\n");
else
pr("NO\n");
}
return ;
} /**************************************************************************************/ int maxx(int a,int b)
{
return a>b?a:b;
} void swapp(int &a,int &b)
{
a^=b^=a^=b;
} int lowbit(int n)
{
return n&(-n);
} int Del_bit_1(int n)
{
return n&(n-);
} int abss(int a)
{
return a>?a:-a;
} double fabss(double a)
{
return a>?a:-a;
} int minn(int a,int b)
{
return a<b?a:b;
}

线性基求交(线段树)--牛客第四场(xor)的更多相关文章

  1. 线性基求交(2019牛客国庆集训派对day4)

    题意:https://ac.nowcoder.com/acm/contest/1109/C 问你有几个x满足A,B集合都能XOR出x. 思路: 就是线性基求交后,有几个基就是2^几次方. #defin ...

  2. 笛卡尔树--牛客第四场(sequence)

    思路: O(n)建一颗笛卡尔树,再O(n)dfs向上合并答案就行了. #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #include &l ...

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

    题意: 传送门 给\(n\)个集合,每个集合有一些数.给出\(m\)个询问,再给出\(l\)和\(r\)和一个数\(v\),问你任意的\(i \in[l,r]\)的集合,能不能找出子集异或为\(v\) ...

  4. POJ 1151 Atlantis 矩形面积求交/线段树扫描线

    Atlantis 题目连接 http://poj.org/problem?id=1151 Description here are several ancient Greek texts that c ...

  5. 带 sin, cos 的线段树 - 牛客

    链接:https://www.nowcoder.com/acm/contest/160/D来源:牛客网 题目描述给出一个长度为n的整数序列a1,a2,...,an,进行m次操作,操作分为两类.操作1: ...

  6. 最短meeting路线(树的直径)--牛客第四场(meeting)

    题意: 给你一棵树,树上有些点是有人的,问你选一个点,最短的(最远的那个人的距离)是多少. 思路: 其实就是树的直径,两遍dfs,dfs第二遍的时候遇到人就更新直径就行了,ans是/2,奇数的话+1. ...

  7. 分层最短路(牛客第四场)-- free

    题意: 给你边权,起点和终点,有k次机会把某条路变为0,问你最短路是多长. 思路: 分层最短路模板题.题目有点坑(卡掉了SPFA,只能用dijkstra跑的算法). #include<iostr ...

  8. %300为0的个数(牛客第四场)-- number

    题意: 给你一串数,问你如题. 思路: 我不是这样的作法,从后往前,先取00,再算%3==0的个数,往前推的时候有递推关系: #define IOS ios_base::sync_with_stdio ...

  9. 3的倍数 或运算构造x(牛客第四场)-- triples I

    题意: 给你一个数,希望你能用最少的3的倍数或运算成它,让你输出答案. 思路: 进制%3有规律,1.2.4.8.16%3是1.2.1.2.1 ... 利用这一点分情况取一些位合成一些数就是答案了. # ...

随机推荐

  1. [BJOI2015]树的同构 && 树哈希教程

    题目链接 有根树的哈希 离散数学中对树哈希的描述在这里.大家可以看看. 判断有根树是否同构,可以考虑将有根树编码.而编码过程中,要求保留树形态的特征,同时忽略子树顺序的不同.先来看一看这个方法: 不妨 ...

  2. 如何在main.js中改变vuex中的值?

    做登录权限控制的时候, 我通过全局路由守卫来去做权限判断,这样的话可能需要在整个项目加载的初期去做一些诸如 接口请求. vuex修改 之类的问题 其实非常简单,直接如图:

  3. MySQL:如何选取Table中的50到100行

    MySQL:如何选取Table中的50到100行 使用查询语句的时候,经常要返回前几条或者中间某几行数据,这个时候怎么办呢?不用担心,MySql已 经为我们提供了这样一个功能. ? 1 2 [sql] ...

  4. LightGBM GPU python版本安装

    失败的安装尝试 1.官方Guide https://lightgbm.readthedocs.io/en/latest/GPU-Windows.html 生成在windows下可执行的exe程序,但是 ...

  5. idea启动报Plugin Error错误的解决办法(亲测有效)

    今天在idea工作时,idea崩溃自动关闭,再打开时报Plugin Error,tomcat无法启动,于是上网查询,看到这个办法,成功解决了我的问题: 找到IDEA的配置文件夹下的disabled_p ...

  6. DP&图论 DAY 3 上午

    DP&图论  DAY 3  上午 状态压缩dp >状态压缩dp ◦状态压缩是设计dp状态的一种方式.◦当普通的dp状态维数很多(或者说维数与输入数据有关),但每一维总量很少是,可以将多维 ...

  7. 3709: [PA2014]Bohater

    3709: [PA2014]Bohater 或者:Bohater 题解 好狠啊这个题 z 要开 long long ,可能算掉血回血的时候会爆 long long 吧 首先把能回血的怪打死(不然你后面 ...

  8. 文笔很差系列4 - Kris Kremo

    转载请标注原链接 https://www.cnblogs.com/xczyd/p/11127671.html Kris Kremo老先生(1951年出生,1970年第一次正式登台,截止2019年练习时 ...

  9. LC 759. Employee Free Time 【lock, hard】

    We are given a list schedule of employees, which represents the working time for each employee. Each ...

  10. Linux之tar命令

    命令格式: tar [-cxzjvf]   压缩打包文档的名称 欲打包目录 参数: -c :建立一个归档文件的参数指令 -x :解开一个归档文件的参数指令! -z :是否需要用 gzip 压缩? -j ...