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. docker 安装 ElasticSearch

    docker pull docker.elastic.co/elasticsearch/elasticsearch:5.6.9 docker images docker run -e ES_JAVA_ ...

  2. 一台电脑同时添加git和bitbucket两个网站的ssh key

    添加第一个ssh key 就不多说了,不懂的可以自己查资料 ssh-keygen -t rsa -C 'email_1@email.com' 然后一路enter就好了 假设已经添加好了git的ssh ...

  3. MyEclipse使用总结——MyEclipse安装maven插件[转]

    打开 myeclipse, MyEclipse -->  Preferences -->Maven4MyEclipse 确定jdk是可用的 选择自己安装的maven: 点击Add选中我们的 ...

  4. Windows安全证书生成方法(开发者证书)

    首先,查看本机安装的证书可在“运行”中输入:certmgr.msc 一.win8.8.1.win10系统,使用管理员powershell创建证书: (1)利用如下命令来创建证书并获取到其指纹 New- ...

  5. 图解SQL的Join

    原文地址:http://coolshell.cn/articles/3463.html 对于SQL的Join,在学习起来可能是比较乱的.我们知道,SQL的Join语法有很多inner的,有outer的 ...

  6. springmvc 文件下载分批读取,防止内存溢出

    参考 https://blog.csdn.net/u014732956/article/details/51404086    

  7. VRRP概述-转

    本文介绍了VRRP的基本原理.特点和应用. VRRP概述 随着Internet的发展,人们对网络的可靠性的要求越来越高.对于局域网用户来说,能够时刻与外部网络保持联系是非常重要的. 通常情况下,内部网 ...

  8. LUOGU 9月 月赛

    T1 签到题 传送门 解题思路 将原式化简一下,让n个1变成 (10^n-1)/9 ,然后再移项,变成了高次同余形式,用bsgs求解.交了好几次都是80,后来才被告知要快速乘. 代码 #include ...

  9. SQL Server中存储过程与函数的区别

    本质上没区别.只是函数有如:只能返回一个变量的限制.而存储过程可以返回多个.而函数是可以嵌入在sql中使用的,可以在select中调用,而存储过程不行.执行的本质都一样. 函数限制比较多,比如不能用临 ...

  10. 深入浅出 Java Concurrency (7): 锁机制 part 2 AQS[转]

    在理解J.U.C原理以及锁机制之前,我们来介绍J.U.C框架最核心也是最复杂的一个基础类:java.util.concurrent.locks.AbstractQueuedSynchronizer. ...