QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#712124 | #8520. Xor Partitions | ucup-team4992# | RE | 1ms | 5724kb | C++20 | 1.3kb | 2024-11-05 14:38:03 | 2024-11-05 14:38:04 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=5e5+5,mod=1e9+7,M=60;
int num[65],pos,n;
ll A[N];
ll sum[65][2];
ll dp[N],fpow[65];
void init(){
fpow[0]=1;
for(int i=1; i<=M; i++) fpow[i]=fpow[i-1]<<1,fpow[i]%=mod;
}
void calc(int x){
pos=0;
while(x){
num[pos++]=x&1;
x>>=1;
}
for(; pos<=M; pos++) num[pos]=0;
}
void solve(){
cin>>n;
for(int i=0; i<=60; i++) sum[i][1]=1;
for(int i=1; i<=n; i++){
ll x;
cin>>x;
calc(x);
for(int j=0; j<=M; j++){
dp[i]+=sum[j][num[j]]*fpow[j]%mod; dp[i]%=mod;
// cout<<"num["<<j<<"] = "<<num[j]<<" , sum["<<j<<"] = "<<sum[j][0]<<" , "<<sum[j][1]<<"\n";
}
// cout<<"dp["<<i<<"] = "<<dp[i]<<"\n";
for(int j=0; j<=M; j++){
if(num[j]) swap(sum[j][0],sum[j][1]);
sum[j][1]+=dp[i]; sum[j][1]%=mod;
// cout<<"num["<<j<<"] = "<<num[j]<<" , sum["<<j<<"] = "<<sum[j][0]<<" , "<<sum[j][1]<<"\n";
}
// cout<<"\n";
}
cout<<dp[n]<<"\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
init();
int T=1;
// cin>>T;
while(T--) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5724kb
input:
4 7 3 1 2
output:
170
result:
ok 1 number(s): "170"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5724kb
input:
1 0
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5636kb
input:
1 1
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5692kb
input:
3 1 2 3
output:
16
result:
ok 1 number(s): "16"
Test #5:
score: 0
Accepted
time: 1ms
memory: 5636kb
input:
4 0 1 0 1
output:
2
result:
ok 1 number(s): "2"
Test #6:
score: -100
Runtime Error
input:
562 918479109239293921 960173570446350728 374394588863436385 418106819278123099 473761712658352147 662782574081105364 824954323015093862 827581845536521847 184394794881199801 820907621998888642 606529830885621237 961790689782125501 582742201855597942 337901250755571075 287706594894797714 18578215893...