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. Java常用英语汇总(面试必备)

    Java常用英语汇总(面试必备) abstract (关键字)             抽象 ['.bstr.kt] access                            vt.访问,存 ...

  2. VS2010-如何建立并运行多个含有main函数的文件

    一.先说两个概念,解决方案与工程 在VS2010中,工程都是在解决方案管理之下的.一个解决方案可以管理多个工程,可以把解决方案理解为多个有关系或者没有关系的工程的集合. 每个应用程序都作为一个工程来处 ...

  3. LocalSessionFactoryBean有几个属性查找hibernate映射文件

    LocalSessionFactoryBean有几个属性查找hibernate映射文件: mappingResources.mappingLocations.mappingDirectoryLocat ...

  4. php面向对象的初认识

    面向对象的基本概念 面向对象的三大特征:继承 封装 多态 类和对象: 类是一个抽象的概念 对象是一个具体的实例 张三是一个对象,李四也是一个对象.王五同样是一个对象..... 他们都隶属于“人”这个“ ...

  5. 数据库insert和update

    1.当使用insert时不能使用where id=?,这是要使用update语句 2.只对一些列插入数据或者更新数据: insert是: insert tb(column1,column2..)val ...

  6. [原创]Java调用PageOffice给Word中的Table赋值

    Word中的table操作需要借助数据区域(DataRegion)实现的,要求数据区域完整的包含了整个Table的内容,这样才可以通过数据区域控制和操作table.因此,要想使用table,则必须在w ...

  7. Python学习day42-数据库的基本操作(1)

    figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...

  8. AppScan的基础使用

    AppScan是用于Web项目的安全测试工具,扫描网站所有url,自动测试是否存在各种类型的漏洞.AppScan安装在Windows环境上,版本越高,规则库越安全,扫描越全面.   1. 打开AppS ...

  9. python 中的 is 方法 总结

    isidentifier: 判断变量名是否合法 iskeyword:是否为内置关键字

  10. tomcat结构图