QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#825037 | #4283. Power of XOR | IvanZhang2009 | WA | 2ms | 7712kb | C++20 | 4.2kb | 2024-12-21 17:05:05 | 2024-12-21 17:05:07 |
Judging History
answer
/*
* __----~~~~~~~~~~~------___
* . . ~~//====...... __--~ ~~
* -. \_|// |||\\ ~~~~~~::::... /~
* ___-==_ _-~o~ \/ ||| \\ _/~~-
* __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~
* _-~~ .=~ | \\-_ '-~7 /- / || \ /
* .~ .~ | \\ -_ / /- / || \ /
* / ____ / | \\ ~-_/ /|- _/ .|| \ /
* |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\
* ' ~-| /| |-~\~~ __--~~
* |-~~-_/ | | ~\_ _-~ /\
* / \ \__ \/~ \__
* _--~ _/ | .-~~____--~-/ ~~==.
* ((->/~ '.|||' -_| ~~-/ , . _||
* -_ ~\ ~~---l__i__i__i--~~_/
* _-~-__ ~) \--______________--~~
* //.-~~~-~_--~- |-------~~~~~~~~
* //.-~~~--\
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* 神兽保佑 永无BUG
*/
/*
* @Description: I want to be the weakest vegetable in the world!
* @Author: I.Z.
*/
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define speMOD 2933256077ll
#define int long long
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define pb push_back
#define REP(i,b,e) for(int i=(b);i<(int)(e);++i)
#define over(x) {cout<<(x)<<endl;return;}
#define lowbit(x) ((x)&(-(x)))
#define cntbit(x) __builtin_popcount(x)
#define deal(v) sort(all(v));v.erase(unique(v.begin(),v.end()),v.end())
#define lbound(v,x) lower_bound(all(v),x)-v.begin()
mt19937 sd(random_device{}());
int qpow(int a,int b,int m=MOD,int res=1){
a%=m;
while(b>0)res=(b&1)?(res*a%m):(res),a=a*a%m,b>>=1;
return res;
}
int exgcd(int x,int y,int &a,int &b){
if(y==0){
a=1;b=0;
return x;
}
int d=exgcd(y,x%y,a,b);
int z=b;
b=a-b*(x/y);
a=z;
return d;
}
int _x_,_y_;
inline int inverse(int x,int y=MOD){
exgcd(x,y,_x_,_y_);
return (_x_+y)%y;
}
int fac[2000005],inv[2000005];
void init(int n){
fac[0]=inv[0]=1;
REP(i,1,n+1)fac[i]=fac[i-1]*i%MOD;
inv[n]=qpow(fac[n],MOD-2);
for(int i=n-1;i>=1;--i)inv[i]=inv[i+1]*(i+1)%MOD;
}
int binom(int x,int y){
return x<y||y<0? 0:fac[x]*inv[y]%MOD*inv[x-y]%MOD;
}
int n,k,m=43;
int a[50];
int b[34000000];
int id[50];
int dp[20][600000];
void Main() {
cin>>n>>k;
REP(i,0,m+1)a[i]=-1;
int c=0;
REP(i,0,n){
int x;
cin>>x;
for(int j=m;j>=0;--j)if((x>>j)&1){
if(a[j]==-1){a[j]=x;++c;break;}
else x^=a[j];
}
}
if(c<=25){
b[0]=0;
vector<int>t;
REP(i,0,m)if(a[i]!=-1)t.pb(a[i]);
REP(i,0,c){
REP(j,0,(1<<i))b[j|(1<<i)]=b[j]^t[i];
}
vector<int>cnt(m+1,0);
REP(i,0,(1<<c))++cnt[__builtin_popcountll(b[i])];
int ans=0;
REP(i,0,m+1)(ans+=qpow(i,k)*cnt[i])%=MOD;
REP(i,c,n)(ans*=2)%=MOD;
over(ans)
}
n=0;int r=0;
for(int i=m;i>=0;--i)if(a[i]!=-1){
for(int j=i-1;j>=0;--j)if(((a[i]>>j)&1)&&a[j]!=-1)a[i]^=a[j];
}else id[i]=n++;
r=n;
vector<int>t;
REP(i,0,m+1)if(a[i]!=-1){
int x=0;
REP(j,0,m+1)if(a[j]==-1){
if((a[i]>>j)&1)x^=(1ll<<id[j]);
}
t.pb(x);
}
dp[0][0]=1;
REP(i,0,n){
for(int j=i;j>=0;--j){
REP(p,0,(1<<r))if(dp[j][p])dp[j+1][p^t[i]]+=dp[j][p];
}
}
vector<int>cnt(m+1,0);
REP(i,0,n+1){
REP(j,0,(1<<r))cnt[i+cntbit(j)]+=dp[i][j];
}
int ans=0;
REP(i,1,m+1)(ans+=cnt[i]*qpow(i,k))%=MOD;
REP(i,c,n)(ans*=2)%=MOD;
cout<<ans<<endl;
}
void TC() {
int tc=1;
while(tc--){
Main();
cout.flush();
}
}
signed main() {
return cin.tie(0),cout.tie(0),ios::sync_with_stdio(0),TC(),0;
}
/*
1. CLEAR the arrays (ESPECIALLY multitests)
2. DELETE useless output
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 7712kb
input:
3 2 1 2 3
output:
12
result:
ok 1 number(s): "12"
Test #2:
score: 0
Accepted
time: 2ms
memory: 7692kb
input:
2 1000000000 1 2
output:
140625003
result:
ok 1 number(s): "140625003"
Test #3:
score: 0
Accepted
time: 2ms
memory: 7628kb
input:
3 4 21 31 15
output:
1076
result:
ok 1 number(s): "1076"
Test #4:
score: 0
Accepted
time: 2ms
memory: 7644kb
input:
4 10 21 16 23 30
output:
3504120
result:
ok 1 number(s): "3504120"
Test #5:
score: 0
Accepted
time: 0ms
memory: 7692kb
input:
5 795325759 23 18 18 15 24
output:
398580583
result:
ok 1 number(s): "398580583"
Test #6:
score: -100
Wrong Answer
time: 2ms
memory: 7616kb
input:
6 425010546 15190825693299 11021868218180 10853490476696 16489831131502 15731786397897 1859285400474
output:
58187104
result:
wrong answer 1st numbers differ - expected: '226806798', found: '58187104'