题意:

给你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. 2019牛客暑期多校训练营(第二场)J

    题意 给一个长度为1e9的只包含1和-1的数列,1的个数不超过1e7,计算有多少对\((l,r)\)满足\(\sum_{i=l}^r a[i]>0\) 分析 dp求出每段连续的1最右端为右端点的 ...

  2. jdk中使用的设计模式

    在JDK(Java Development Kit)类库中,开发人员使用了大量设计模式,正因为如此,我们可以在不修改JDK源码的前提下开发出自己的应用软件,研究JDK类库中的模式实例也不失为学习如何使 ...

  3. 推荐系统系列(三):FNN理论与实践

    背景 在FM之后出现了很多基于FM的升级改造工作,由于计算复杂度等原因,FM通常只对特征进行二阶交叉.当面对海量高度稀疏的用户行为反馈数据时,二阶交叉往往是不够的,三阶.四阶甚至更高阶的组合交叉能够进 ...

  4. BZOJ 2959 长跑 (LCT、并查集)

    题目链接 https://www.lydsy.com/JudgeOnline/problem.php?id=2959 题解 真是被这题搞得心态大崩--调了7个小时--然而并查集都能写成\(O(n^2) ...

  5. AWS EC2 PV Drivers 驱动升级

    问题 从2019-10-23起,我的AWS实例不断的重启(大概6个小时左右),或者连接不上(远程连接不上并PING不通IP),但控制台显示running. 分析与解决方法 通过查看dump文件,发现是 ...

  6. SRS之RTMP连接处理线程conn:接收客户端推流

    由 SRS之RTMP的TCP线程 分析可知,SRS 接受客户端的连接后创建了一个线程:conn,用于处理与客户端的 RTMP 连接. 本文的分析是基于该配置文件的: listen 1935; max_ ...

  7. LeetCode 88. 合并两个有序数组(Merge Sorted Array)

    题目描述 给定两个有序整数数组 nums1 和 nums2,将 nums2 合并到 nums1 中,使得 num1 成为一个有序数组. 说明: 初始化 nums1 和 nums2 的元素数量分别为 m ...

  8. CMD命令行管道命令

    一.什么是管道命令 管道命令能够将一个命令的执行结果经过筛选,只保留我们需要的信息. 如 dir 命令会显示目录下所有文件夹和文件,可以使用管道命令| findstr "" 将di ...

  9. Vue -3:单文件组件

    在很多 Vue 项目中,我们使用 Vue.component 来定义全局组件,紧接着用 new Vue({ el: '#container '}) 在每个页面内指定一个容器元素. 这种方式在很多中小规 ...

  10. to_datetime 以及 dt.days、dt.months

    Series类型的数据,经过 to_datetime 之后就可以用 pandas.Series.dt.day 和 pandas.Series.pd.month. import pandas as pd ...