BZOJ2844: albus就是要第一个出场(线性基)
Time Limit: 6 Sec Memory Limit: 128 MB
Submit: 2054 Solved: 850
[Submit][Status][Discuss]
Description
Input
第一行一个数n, 为序列A的长度。接下来一行n个数, 为序列A, 用空格隔开。最后一个数Q, 为给定的数.
Output
Sample Input
1 2 3
1
Sample Output
样例解释:
N = 3, A = [1 2 3]
S = {1, 2, 3}
2^S = {空, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}}
f(空) = 0
f({1}) = 1
f({2}) = 2
f({3}) = 3
f({1, 2}) = 1 xor 2 = 3
f({1, 3}) = 1 xor 3 = 2
f({2, 3}) = 2 xor 3 = 1
f({1, 2, 3}) = 0
所以
B = [0, 0, 1, 1, 2, 2, 3, 3]
HINT
数据范围:
1 <= N <= 10,0000
其他所有输入均不超过10^9
Source

- // luogu-judger-enable-o2
- #include<cstdio>
- #include<cstring>
- #include<algorithm>
- #include<queue>
- #define int long long
- using namespace std;
- const int MAXN = 1e5 + , B = , mod = ;
- inline int read() {
- char c = getchar(); int x = , f = ;
- while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
- while(c >= '' && c <= '') x = x * + c - '', c = getchar();
- return x * f;
- }
- int N, a[MAXN], P[MAXN];
- void Insert(int x) {
- for(int i = B; i >= ; i--) {
- if((x >> i) & ) {
- if(!P[i]) {P[i] = x; return ;}
- x = x ^ P[i];
- }
- }
- }
- void Gauss() {
- for(int i = B; i >= ; i--)
- if(P[i])
- for(int j = i + ; j <= B; j++)
- if((P[j] >> i) & )
- P[j] ^= P[i];
- }
- int num = , pos[MAXN];
- void ReMove() {
- for(int i = ; i <= B; i++)
- if(P[i])
- pos[++num] = i;
- }
- int fastpow(int a, int p) {
- int base = ;
- while(p) {
- if(p & ) base = (base * a) % mod;
- a = (a * a) % mod; p >>= ;
- }
- return base;
- }
- main() {
- #ifdef WIN32
- freopen("a.in", "r", stdin);
- #endif
- N = read();
- for(int i = ; i <= N; i++) a[i] = read(), Insert(a[i]);
- Gauss();
- ReMove();
- int Q = read(), ans = ;
- for(int i = ; i <= num; i++)
- if((Q & (1ll << pos[i])))
- ans = ans ^ ( << i - );
- printf("%lld\n", (ans * fastpow(, N - num) + ) % mod);
- }
BZOJ2844: albus就是要第一个出场(线性基)的更多相关文章
- bzoj 2844 albus就是要第一个出场 - 线性基
题目传送门 这是个通往vjudge的虫洞 这是个通往bzoj的虫洞 题目大意 给定集合$S$,现在将任意$A\subseteq S$中的元素求异或和,然后存入一个数组中(下标从1开始),然后从小到大排 ...
- albus就是要第一个出场(线性基)
传送门 这个题题目描述真怪异--就不能说人话吗-- 人话:给定长为n的序列A,定义f(s)为集合s内所有元素异或值,求A的所有子集的f值从小到大排列后,q在其中第一次出现的下标对10086取模的值. ...
- 【贪心】【线性基】bzoj2844 albus就是要第一个出场
引用题解:http://blog.csdn.net/PoPoQQQ/article/details/39829237 注意评论区. #include<cstdio> using names ...
- 【线性基】bzoj2844: albus就是要第一个出场
线性基求可重rank 题目描述 给定 n 个数 $\{ a_i \}$ ,以及数 $x$. 将 $\{ a_i \}$ 的所有子集(包括空集)的异或值从小到大排序,得到 $\{ b_i \} $. ...
- BZOJ2844: albus就是要第一个出场
Description 已知一个长度为n的正整数序列A(下标从1开始), 令 S = { x | 1 <= x <= n }, S 的幂集2^S定义为S 所有子集构成的集合. 定义映射 f ...
- bzoj千题计划195:bzoj2844: albus就是要第一个出场
http://www.lydsy.com/JudgeOnline/problem.php?id=2844 题意:给定 n个数,把它的所有子集(可以为空)的异或值从小到大排序得到序列 B,请问 Q 在 ...
- 【BZOJ2844】albus就是要第一个出场 高斯消元求线性基
[BZOJ2844]albus就是要第一个出场 Description 已知一个长度为n的正整数序列A(下标从1开始), 令 S = { x | 1 <= x <= n }, S 的幂集2 ...
- CF895C: Square Subsets && 【BZOJ2844】albus就是要第一个出场
CF895C: Square Subsets && [BZOJ2844]albus就是要第一个出场 这两道题很类似,都是线性基的计数问题,解题的核心思想也一样. CF895C Squa ...
- BZOJ 2844: albus就是要第一个出场 [高斯消元XOR 线性基]
2844: albus就是要第一个出场 题意:给定一个n个数的集合S和一个数x,求x在S的$2^n$个子集从小到大的异或和序列中最早出现的位置 一开始看错题了...人家要求的是x第一次出现位置不是第x ...
随机推荐
- centos-7.2 node.js免编译安装
cd /usr/local/ wget https://npm.taobao.org/mirrors/node/v8.9.3/node-v8.9.3-linux-x64.tar.gz tar -zxv ...
- Elipse plugin or Bundle & OSGI
Develop and register service, lookup and use service! Android Design on service's publish-find-bind ...
- Sde各类命令详解(sdemon 、sdelayer、sdeservice、sdetable、sdeconfig、SdeExport_SdeImport)
Sdemon命令详解: http://wenku.baidu.com/view/3b53e8ec0975f46527d3e1c2.html 1.重建空间索引 D:\Program Fi ...
- htmlunit模拟登录
htmlunit jar项目路径http://sourceforge.net/projects/htmlunit/files/htmlunit/ demo代码如下 public class AutoL ...
- 【Leetcode】【Easy】Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...
- 通过vue-cli3构建一个SSR应用程序
1.前沿 1.1.什么是SSR SSR(服务端渲染)顾名思义就是将页面在服务端渲染完成后在客户端直接展示. 1.2.客户端渲染与服务端渲染的区别 传统的SPA模式 即客户端渲染的模式 Vue.js构建 ...
- Quartus II管脚批量分配文件(.tcl)格式
package require ::quartus::project set_location_assignment PIN_E1 -to clk set_location_assignment PI ...
- 关于simotion建立同步/解除同步的问题
关于simotion建立同步/解除同步的问题. 问题: [enable gearing][disable gearing][enable camming][disable camming]都是一个过程 ...
- NO.002-2018.02.07《越人歌》先秦:佚名
参考之后略有修改,疑问点“不訾诟耻”释义 越人歌原文.翻译及赏析_古诗文网 蒙羞被好兮不訾诟耻_释义_吴江诗词网 越人歌 先秦:佚名 今夕何夕兮,搴舟中流.今晚是怎样的晚上啊河中漫游.搴(qiān ...
- selenium+python自动化登录脚本
利用selenium+python写的一个关于登录的自动化脚本