# [BZOJ 2844] albus就是要第一个出场

## 2844: albus就是要第一个出场

Time Limit: 6 Sec  Memory Limit: 128 MB
Submit: 2316  Solved: 964
[Submit][Status][Discuss]

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

## 题解

(其实样例有一定暗示...但是数据太小并不是很令人信服...)

### 代码实现

 1 #include <bits/stdc++.h>
2
3 const int MOD=10086;
4 const int MAXN=1e5+10;
5
6 int n;
7 int k;
8 int pos[MAXN];
9 int base[MAXN];
10
11 int Pow(int,int,int);
12
13 int main(){
14     scanf("%d",&n);
15     for(int i=0;i<n;i++){
16         int x;
17         scanf("%d",&x);
18         for(int p=30;p>=0;p--){
19             if((1<<p)&x){
20                 if(base[p])
21                     x^=base[p];
22                 else{
23                     base[p]=x;
24                     break;
25                 }
26             }
27         }
28     }
29     int x;
30     scanf("%d",&x);
31     for(int i=0;i<=30;i++){
32         if(base[i]){
33             pos[k]=i;
34             base[k++]=base[i];
35         }
36     }
37     int ans=0;
38     for(int i=0;i<k;i++){
39         if((1<<pos[i])&x){
40             ans^=(1<<i);
41         }
42     }
43     printf("%d\n",(ans%MOD*Pow(2,n-k,MOD)+1)%MOD);
44     return 0;
45 }
46
47 int Pow(int a,int n,int p){
48     int ans=1;
49     while(n>0){
50         if(n&1)
51             ans=1ll*a*ans%p;
52         a=1ll*a*a%p;
53         n>>=1;
54     }
55     return ans;
56 }
BZOJ 2844

posted @ 2018-12-28 19:23  rvalue  阅读(300)  评论(0编辑  收藏  举报