xor

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 524288K,其他语言1048576K
64bit IO Format: %lld

题目描述

Your are given n sets.Every set contains some integers.

We say a set can express an integer, only when there exists a subset of the set such that the bitwise-xor of the elements in the subset is equal to that integer.

Now you need to answer m queries. Each query will give you three integers l,r,x and you should answer if for every i∈[l,r] ,the i-th set can express x.

输入描述:

The first line contains two integers n,m.

For each of the following n lines, the first integer sz stands for the size of this set and the following sz integers stand for the elements in this set. The sets are described from number 1 to n.

For each of the following m lines, there're three integers l,r,x that means a query.

输出描述:

For each query, output a line.

If for every i∈[l,r] ,the i-th set can express x, you need to print “YES”, and "NO" otherwise.

输入

1 3
2 1 2
1 1 0
1 1 3
1 1 4

输出

YES
YES
NO

备注:

1≤n,m≤50000,1≤sz≤32,1≤l≤r≤n ,the every integer in input ∈[0,232)。
链接:https://ac.nowcoder.com/acm/contest/884/B
来源:牛客网

线性基,Mark一下线性基的交。
#include<bits/stdc++.h>
using namespace std; const int Digit=; struct L_B
{
long long basis[Digit+];
L_B()
{
memset(basis,,sizeof(basis));
} void operator = (const L_B & s)
{
for(int i=; i<=Digit; i++)basis[i]=s.basis[i];
} bool insert(long long val)
{
for (int i=Digit; i>=; i--)
if (val&(1LL<<i))
{
if (!basis[i])
{
basis[i]=val;
break;
}
val^=basis[i];
}
return val>;
} bool check(long long val)
{
for (int i=Digit; i>=; i--)
if (val&(1LL<<i))
{
if(basis[i])val^=basis[i];
else
return ;
}
return ;
} long long query_max()
{
long long ret=;
for (int i=Digit;i>=;i--)
if ((ret^basis[i])>ret)
ret^=basis[i];
return ret;
} }; L_B Merge(L_B A,L_B B)
{
L_B All, C, D;
for (int i = Digit; i >= ; i--)
{
All.basis[i] = A.basis[i];
D.basis[i] = 1ll << i;
}
for (int i = Digit; i >= ; i--)
{
if (B.basis[i])
{
long long v = B.basis[i], k = ;
bool can = true;
for (int j = Digit; j >= ; j--)
{
if (v & (1ll << j))
{
if (All.basis[j])
{
v ^= All.basis[j];
k ^= D.basis[j];
}
else
{
can = false;
All.basis[j] = v;
D.basis[j] = k;
break;
}
}
} if (can)
{
long long v = ;
for (int j = Digit; j >= ; j--)
{
if (k & (1ll << j))
{
v ^= A.basis[j];
}
}
C.insert(v);
}
}
}
return C;
} const int N = 5e4+;
struct ss
{
int l,r;
L_B lb;
};
L_B base[N];
ss tree[*N]; void build(int v,int l,int r)
{
int mid=(l+r)/;
tree[v].l=l;
tree[v].r=r; if(l==r)
{
tree[v].lb=base[l];
return;
} build(*v,l,mid);
build(*v+,mid+,r); tree[v].lb=Merge(tree[*v].lb,tree[*v+].lb);
} bool query(int v,int l,int r,int x)
{
// printf("%d %d %d\n",tree[v].l,tree[v].r,x);
if(tree[v].l==l&&tree[v].r==r)return tree[v].lb.check(x); int mid=(tree[v].l+tree[v].r)/;
if(r<=mid)return query(*v,l,r,x);
else
if(l>mid)return query(*v+,l,r,x);
else
{
return query(*v,l,mid,x)&&query(*v+,mid+,r,x);
}
} int main()
{
int n,m;
scanf("%d %d",&n,&m);
for(int i=;i<=n;i++)
{
int sz;
scanf("%d",&sz);
while(sz--)
{
int a;
scanf("%d",&a);
base[i].insert(a);
}
} build(,,n);
while(m--)
{
int l,r,x;
scanf("%d %d %d",&l,&r,&x);
printf("%s\n",query(,l,r,x) ? "YES" : "NO");
}
return ;
}

xor的更多相关文章

  1. [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字

    Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...

  2. 二分+DP+Trie HDOJ 5715 XOR 游戏

    题目链接 XOR 游戏 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  3. BZOJ 2115 【Wc2011】 Xor

    Description Input 第一行包含两个整数N和 M, 表示该无向图中点的数目与边的数目. 接下来M 行描述 M 条边,每行三个整数Si,Ti ,Di,表示 Si 与Ti之间存在 一条权值为 ...

  4. xor和gates的专杀脚本

    前段时间的一次样本,需要给出专杀,应急中遇到的是linux中比较常见的两个家族gates和xor. 首先是xor的专杀脚本,xor样本查杀的时候需要注意的是样本的主进程和子进程相互保护(详见之前的xo ...

  5. Codeforces617 E . XOR and Favorite Number(莫队算法)

    XOR and Favorite Number time limit per test: 4 seconds memory limit per test: 256 megabytes input: s ...

  6. Xor && 线性基练习

    #include <cstdio> #include <cstring> ; ; int cnt,Ans,b,x,n; inline int Max(int x,int y) ...

  7. BC之Claris and XOR

    http://acm.hdu.edu.cn/showproblem.php?pid=5661 Claris and XOR Time Limit: 2000/1000 MS (Java/Others) ...

  8. 异或链表(XOR linked list)

    异或链表(Xor Linked List)也是一种链式存储结构,它可以降低空间复杂度达到和双向链表一样目的,任何一个节点可以方便的访问它的前驱节点和后继结点.可以参阅wiki 普通的双向链表 clas ...

  9. hdu 5661 Claris and XOR

    Claris and XOR Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  10. [BZOJ 2819]NIM(dfs序维护树上xor值)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=2819 分析: 树上的nim游戏,关键就是要判断树上的一条链的异或值是否为0 这个题目有 ...

随机推荐

  1. videojs实现双击视频全屏播放、播放器全屏时视频未全屏

    https://blog.csdn.net/staritstarit/article/details/78451963 暂停时只能使用左下角的暂停按钮,点击视频时不再响应 使用width和height ...

  2. 国内平台比特币(Bitcoin)搬砖流程教学

    建议搬砖时要的价差,实际费用与利润请自行计算,避免亏损或白做工请自行拿捏利润. 请搬砖前要先自行操作与确认双边平台的存取速度.利於拿捏时间,避免时间差导致亏损. (所有内容 仅供参考 盈亏自负) 搬砖 ...

  3. HDU 1069 Monkey and Banana (动态规划)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 简单记录一下 思路:把长方体的各种摆法都存到数组里面,然后按照长宽排序,再dp即可 转移方程 d ...

  4. linux下安装rabbitmq 集群

    1.下载erlang官网地址 http://www.erlang.org/download 挑选合适的版本 然后 wget 比如目前18.3运行命令 wget http://erlang.org/do ...

  5. 运行第一个python程序,python 变量,常量,注释

    一.运行第一个python程序: print('Hello,world') 保存为.py文件 在cmd窗口: python3x:python  py文件路径 回车 python2x:python  p ...

  6. vue 关闭微信浏览器(返回路由为undefined时)

    参考:https://blog.csdn.net/KingJin_CSDN_/article/details/77050569 main.js: import router from './route ...

  7. HBase 数据坐标

  8. 排列组合lucas模板

    //codeforces 559C|51nod1486 Gerald and Giant Chess(组合数学+逆元) #include <bits/stdc++.h> using nam ...

  9. T2988 删除数字【状压Dp+前缀和优化】

    Online Judge:从Topcoder搬过来,具体哪一题不清楚 Label:状压Dp+前缀和优化 题目描述 给定两个数A和N,形成一个长度为N+1的序列,(A,A+1,A+2,...,A+N-1 ...

  10. List -- 循环操作

    1,单元循环 for…in 2,索引循环 for…in range(len(List)) 3,同时循环单元和索引 使用enumerate: for index, item in enumerate(L ...