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. promise体验

    promise的执行流程 promise串行执行异步 job1.then(job2).then(job3).catch(handleError); // 0.5秒后返回input*input的计算结果 ...

  2. 洛谷P1291 [SHOI2002]百事世界杯之旅

    题目链接: kma 题目分析: 收集邮票的弱弱弱弱化版,因为是期望,考虑倒推 设\(f[i]\)表示现在已经买齐了\(i\)种,距离买完它的剩余期望次数 那么下一次抽有\(\frac{i}{n}\)的 ...

  3. idea配置tomcat中war和war exploded的区别

    是选择war还是war exploded 这里首先看一下他们两个的区别: war模式:将WEB工程以包的形式上传到服务器 :war exploded模式:将WEB工程以当前文件夹的位置关系上传到服务器 ...

  4. poi 3669 meteor shower (bfs)

    题目链接:http://poj.org/problem?id=3669 很基础的一道bfs的题,然而,我却mle了好多次,并且第二天才发现错在了哪里_(:з)∠)_ 写bfs或者dfs一定要记得对走过 ...

  5. PAT甲级——A1097 Deduplication on a Linked List

    Given a singly linked list L with integer keys, you are supposed to remove the nodes with duplicated ...

  6. python学习笔记3.1_数据读取常用函数参数

    一.read_table/read_csv常用函数参数 1.path:表明文件系统位置的字符串.url或文件型对象 2.sep或delimiter:用于分隔每行字段的字符序列或正则表达式 3.head ...

  7. mybatis 中 if else 用法

    mybaits 中没有 else 要用 chose when otherwise 代替 下面就是MyBatis中的if....else...表示方法 <choose> <when t ...

  8. 跟我一起在Win10中用VMware安装Ubuntu

    VMware下安装Ubuntu 打开VMware,创建虚拟机: 点击运行虚拟机,报错为 解决办法为 大功告成,我们已经在Win10中用VMware安装Ubuntu了

  9. 留下来做项目经理还是跳槽学Java

    毕业两年了,曾经给自己计划工作两年后跳一次槽,去尝试学习更多的东西.2012年7月5日入职,现在整整两年,最近面临这样的一个抉择:是留在公司继续做项目经理,还是跳槽去学习Java. 我的基本情况:本科 ...

  10. MyBatis Plus之like模糊查询中包含有特殊字符(_、\、%)

    传统的解决思路:自定义一个拦截器,当有模糊查询时,模糊查询的关键字中包含有上述特殊字符时,在该特殊字符前添加\进行转义处理. 新的解决思路:将like 替换为 MySQL内置函数locate函数 参考 ...