QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#528632 | #8520. Xor Partitions | deepthought | WA | 1ms | 4412kb | C++23 | 1.8kb | 2024-08-23 17:26:21 | 2024-08-23 17:26:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN = 3e5+5;
ll MOD = 1e9 + 7;
ll bitsum[MAXN][63][2];
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector <ll> pow2(63, 0);
pow2[0] = 1;
for(int i = 1; i <= 62; i++) pow2[i] = pow2[i - 1] * 2;
vector <ll> a(n + 1);
vector <ll> xp(n + 1, 0);
for(int i = 1; i <= n; i++){
cin >> a[i];
xp[i] = a[i] ^ xp[i - 1];
}
vector <ll> dp(n + 1, 0);
dp[1] = a[1];
for(int j = 0; j < 63; j++) {
if(pow2[j] & xp[1]) {
bitsum[1][j][1] = (bitsum[1][j][1] + dp[1]) % MOD;
}
else {
bitsum[1][j][0] = (bitsum[1][j][0] + dp[1]) % MOD;
}
}
for(int i = 2; i <= n; i++) {
for(int j = 0; j < 63; j++) {
if(pow2[j] & xp[i]) {
dp[i] = (dp[i] + bitsum[i - 1][j][0] * pow2[j]) % MOD;
// cout << j << " " << bitsum[i - 1][j][0] << endl;
}
else {
dp[i] = (dp[i] + bitsum[i - 1][j][1] * pow2[j]) % MOD;
// cout << j << " " << bitsum[i - 1][j][1] << endl;
}
}
dp[i] = (dp[i] + xp[i]) % MOD;
for(int j = 0; j < 63; j++) {
bitsum[i][j][1] = bitsum[i - 1][j][1];
bitsum[i][j][0] = bitsum[i - 1][j][0];
if(pow2[j] & xp[i]) {
bitsum[i][j][1] = (bitsum[i][j][1] + dp[i]) % MOD;
}
else {
bitsum[i][j][0] = (bitsum[i][j][0] + dp[i]) % MOD;
}
}
// cout << i << " " << dp[i] << endl;
}
cout << dp[n] << endl;
}
/*
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3656kb
input:
4 7 3 1 2
output:
170
result:
ok 1 number(s): "170"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
1 0
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
1 1
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
3 1 2 3
output:
16
result:
ok 1 number(s): "16"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
4 0 1 0 1
output:
2
result:
ok 1 number(s): "2"
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 4412kb
input:
562 918479109239293921 960173570446350728 374394588863436385 418106819278123099 473761712658352147 662782574081105364 824954323015093862 827581845536521847 184394794881199801 820907621998888642 606529830885621237 961790689782125501 582742201855597942 337901250755571075 287706594894797714 18578215893...
output:
196095239
result:
wrong answer 1st numbers differ - expected: '641941658', found: '196095239'