xor
xor
空间限制:C/C++ 524288K,其他语言1048576K
64bit IO Format: %lld
题目描述
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的更多相关文章
- [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 ...
- 二分+DP+Trie HDOJ 5715 XOR 游戏
题目链接 XOR 游戏 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- BZOJ 2115 【Wc2011】 Xor
Description Input 第一行包含两个整数N和 M, 表示该无向图中点的数目与边的数目. 接下来M 行描述 M 条边,每行三个整数Si,Ti ,Di,表示 Si 与Ti之间存在 一条权值为 ...
- xor和gates的专杀脚本
前段时间的一次样本,需要给出专杀,应急中遇到的是linux中比较常见的两个家族gates和xor. 首先是xor的专杀脚本,xor样本查杀的时候需要注意的是样本的主进程和子进程相互保护(详见之前的xo ...
- Codeforces617 E . XOR and Favorite Number(莫队算法)
XOR and Favorite Number time limit per test: 4 seconds memory limit per test: 256 megabytes input: s ...
- Xor && 线性基练习
#include <cstdio> #include <cstring> ; ; int cnt,Ans,b,x,n; inline int Max(int x,int y) ...
- BC之Claris and XOR
http://acm.hdu.edu.cn/showproblem.php?pid=5661 Claris and XOR Time Limit: 2000/1000 MS (Java/Others) ...
- 异或链表(XOR linked list)
异或链表(Xor Linked List)也是一种链式存储结构,它可以降低空间复杂度达到和双向链表一样目的,任何一个节点可以方便的访问它的前驱节点和后继结点.可以参阅wiki 普通的双向链表 clas ...
- hdu 5661 Claris and XOR
Claris and XOR Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- [BZOJ 2819]NIM(dfs序维护树上xor值)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=2819 分析: 树上的nim游戏,关键就是要判断树上的一条链的异或值是否为0 这个题目有 ...
随机推荐
- springboot让内置tomcat失效
一.POM(去除内嵌tomcat后,需要添加servlet依赖) <dependency> <groupId>org.springframework.boot</grou ...
- Failed to load resource: net::ERR_INSECURE_RESPONSE 问题解决记录
项目在小米自带浏览器中出现了文件丢失.经检查发现这些链接引用全部是完整的线上url.改为相对路径问题解决. 同时消失的bug还有一个Error in event handler for runtime ...
- HttpUrlConnection post 乱码 终极解决方案
今天遇到了java后台模拟http请求,以POST方式传参中文乱码,google了一下,大部分是在打开的HttpURLConnection的输入流的时候设置编码(utf-8),按照设置,试了下并没有解 ...
- Redis深度历险——核心原理与应用实践
高可用架构」的各位老铁们,你们好!你是否还记得上个月发布的文章中,有两篇深入讲解Redis的文章,分别是和,广大粉丝读者们对这两篇文章整体评价颇高.而我就是这两篇文章的原创作者「老钱」(钱文品),我是 ...
- phpCOW机制详解
写时复制(Copy-on-Write,也缩写为COW),顾名思义,就是在写入时才真正复制一份内存进行修改. COW最早应用在*nix系统中对线程与内存使用的优化,后面广泛的被使用在各种编程语言中,如C ...
- iOS开发CoreData的简单使用
1.简介 CoreData是iOS5后,苹果提供的原生的用于对象化管理数据并且持久化的框架.iOS10苹果对CoreData进一步进行了封装,而且效率更高!相关类的简单介绍: NSManagedObj ...
- Django项目: 项目环境搭建 ---- 二、django项目设置
1.配置模板文件 TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.p ...
- <每日一题>题目25:快速排序
''' 快速排序:分而治之,一分为二进行排序 ''' import cProfile import random def quick_sort(nums): if len(nums) <= 1: ...
- 【51nod 1874】 奇怪的数学题
题目 求 \[\sum_{i=1}^n\sum_{j=1}^nsgcd(i,j)^k\] 首先这个次大公约数显然就是\(gcd\)除一下最小质因子了 于是 \[\sum_{i=1}^n\sum_{j= ...
- FPFH+ICP点云配准
A, UniformSampling降噪 B, ISS计算关键点, FPFH特征 在FeatureCloud::setInputCloud中读入点云,并调用processInput进行处理: proc ...