QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#556365#8520. Xor PartitionsDjangle162857#WA 0ms3824kbC++141.1kb2024-09-10 17:21:582024-09-10 17:21:59

Judging History

你现在查看的是最新测评结果

  • [2024-09-10 17:21:59]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3824kb
  • [2024-09-10 17:21:58]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1000000007;
ll up(ll x)
{
	return (x % mod + mod) % mod;
}
void solve()
{
	int n;
	cin >> n;
	vector<ll> a(n + 1, 0), s(n + 1, 0), ans(n + 1, 0);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		s[i] = s[i - 1] ^ a[i];
	}
	vector<array<ll, 2>> add(64);
	for (int i = 1; i <= n; i++) {
		for (ll j = 60; j >= 0; j--) {
			if (s[i] >> j & 1) {
				ans[i] += add[j][1];
			}
			else {
				ans[i] += add[j][0];
			}
		}
		ans[i] += s[i];
		// cout << ans[i] << endl;
		for (ll j = 0; j <= 60; j++) {
			ll res = (1ll << j) % mod;
			if (s[i] >> j & 1) {
				add[j][0] += ans[i] * res % mod;
				add[j][0] = up(add[j][0]);
			}
			else {
				add[j][1] += ans[i] * res % mod;
				add[j][1] = up(add[j][1]);
			}
		}
		/*for (int j = 0; j <= 3; j++) {
			cout << j << " " << add[j][0] << " " << add[j][1] << endl;
		}
		cout << i << " " << ans[i] << endl;*/
	}
	cout << ans[n] << endl;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	while (T--)
		solve();
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3824kb

input:

4
7 3 1 2

output:

170

result:

ok 1 number(s): "170"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3808kb

input:

1
0

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3596kb

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3528kb

input:

3
1 2 3

output:

16

result:

ok 1 number(s): "16"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3824kb

input:

4
0 1 0 1

output:

2

result:

ok 1 number(s): "2"

Test #6:

score: -100
Wrong Answer
time: 0ms
memory: 3536kb

input:

562
918479109239293921 960173570446350728 374394588863436385 418106819278123099 473761712658352147 662782574081105364 824954323015093862 827581845536521847 184394794881199801 820907621998888642 606529830885621237 961790689782125501 582742201855597942 337901250755571075 287706594894797714 18578215893...

output:

416075936223239687

result:

wrong answer 1st numbers differ - expected: '641941658', found: '416075936223239687'