BZOJ2844: albus就是要第一个出场(线性基)

Time Limit: 6 Sec  Memory Limit: 128 MB
Submit: 2054  Solved: 850
[Submit][Status][Discuss]

Description

已知一个长度为n的正整数序列A(下标从1开始), 令 S = { x | 1 <= x <= n }, S 的幂集2^S定义为S 所有子
集构成的集合。定义映射 f : 2^S -> Zf(空集) = 0f(T) = XOR A[t] , 对于一切t属于T现在albus把2^S中每个集
合的f值计算出来, 从小到大排成一行, 记为序列B(下标从1开始)。 给定一个数, 那么这个数在序列B中第1
次出现时的下标是多少呢?

Input

第一行一个数n, 为序列A的长度。接下来一行n个数, 为序列A, 用空格隔开。最后一个数Q, 为给定的数.

Output

共一行, 一个整数, 为Q在序列B中第一次出现时的下标模10086的值.
 

Sample Input

3
1 2 3
1

Sample Output

3
样例解释:
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

 
这种题自己根本想不出来啊qwq。。。

 

 
// luogu-judger-enable-o2
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define int long long 
using namespace std;
const int MAXN = 1e5 + 10, B = 61, mod = 10086;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int N, a[MAXN], P[MAXN];
void Insert(int x) {
    for(int i = B; i >= 0; i--) {
        if((x >> i) & 1) {
            if(!P[i]) {P[i] = x; return ;}
            x = x ^ P[i];
        }
    }
}
void Gauss() {
    for(int i = B; i >= 0; i--) 
        if(P[i]) 
            for(int j = i + 1; j <= B; j++)
                if((P[j] >> i) & 1)
                    P[j] ^= P[i];
}
int num = 0, pos[MAXN];
void ReMove() {
    for(int i = 0; i <= B; i++)
        if(P[i])
            pos[++num] = i;
}
int fastpow(int a, int p) {
    int base = 1;
    while(p) {
        if(p & 1) base = (base * a) % mod;
        a = (a * a) % mod; p >>= 1;
    }
    return base;
}
main() { 
#ifdef WIN32
    freopen("a.in", "r", stdin);
#endif
    N = read();
    for(int i = 1; i <= N; i++) a[i] = read(), Insert(a[i]);
    Gauss();
    ReMove();
    int Q = read(), ans = 0;
    for(int i = 1; i <= num; i++) 
        if((Q & (1ll << pos[i]))) 
            ans = ans ^ (1 << i - 1);    
    printf("%lld\n", (ans * fastpow(2, N - num) + 1) % mod);
}

 

posted @ 2018-06-17 18:10  自为风月马前卒  阅读(283)  评论(2编辑  收藏  举报

Contact with me