UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#203540#3566. T1tkswls100326ms2040kbC++111.7kb2024-02-27 10:03:572024-02-27 13:03:07

answer

#include <bits/stdc++.h>
#define int long long
#pragma GCC optimize(2)
using namespace std;
const int mod = 998244353;
int n, a[100005], b[35][2], g[100005], c[35], d[35], f[35][2], ans, sum[35];
inline int ksm(int p, int q = mod - 2) {
	int base = 1;
	while (q) {
		if (q & 1) base = base * p % mod;
		q >>= 1;
		p = p * p % mod;
	}
	return base;
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for (int i = 0; i <= 29; i++) c[i] = 1, sum[i] = 1;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		for (int j = 0; j <= 29; j++) {
			b[j][(a[i] >> j) & 1]++;
			if (a[i] & (1 << (j))) {
			} else {
//				cout << j << ' ' << c[j] << " " << a[j] << ' ' << ((a[j]) & ((1 << (j)) - 1)) + 1 << "**\n";
				c[j] *= ((a[i]) & ((1 << (j)) - 1)) + 1;
				c[j] %= mod;
				sum[j] *= ((a[i]) & ((1 << (j)) - 1)) + 1;
				sum[j] %= mod;
			}
		}
	}
	int p, q, u, v;
	for (int j = 0; j <= 29; j++) {
		f[j][0] = c[j];
		f[j][1] = 0;
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= 29; j++) {
			if (a[i] & (1 << (j))) {
				p = f[j][0], q = f[j][1];
				f[j][0] = f[j][1] = 0;
				u = (1 << j), v = ((a[i]) & ((1 << (j)) - 1) ) + 1;
//				cout << i << " " << j << ' ' << u << ' ' << v << ' ' << p << ' ' << q << "\n";
				f[j][1] = (p * v % mod + q * u % mod) % mod, f[j][0] = (p * u % mod + q * v % mod) % mod;
				sum[j] *= v;
				sum[j] %= mod;
			}
		}
	}
	for (int i = 29; i >= 0; i--) {
//		cout << b[i][0] << ' ' << b[i][1] << ' ' << f[i][0] << " " << f[i][1] << " " << sum[i] << ' ' << i << "[]\n";
		if (b[i][1] & 1) {
			ans += f[i][0] * ksm(1 << (i)) % mod;
			ans %= mod;
			break;
		} else {
			ans += (f[i][0] - sum[i] + mod) % mod * ksm(1 << (i)) % mod;
		}
	}
	cout << ans;
}

Details

小提示:点击横条可展开更详细的信息

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 0ms
memory: 1260kb

input:

10
3 5 0 1 0 3 5 4 2 5

output:

13248

result:

ok 1 number(s): "13248"

Subtask #2:

score: 10
Accepted

Test #2:

score: 10
Accepted
time: 28ms
memory: 2040kb

input:

100000
25 0 7 1 42 27 29 17 26 23 11 4 24 40 31 10 6 16 26 26 46 27 7 32 9 33 17 15 4 44 36 29 19 17...

output:

460821675

result:

ok 1 number(s): "460821675"

Subtask #3:

score: 10
Accepted

Test #3:

score: 10
Accepted
time: 28ms
memory: 2040kb

input:

100000
14 25 9 27 9 33 48 28 10 29 28 39 50 33 8 18 38 0 34 25 13 7 30 48 13 39 14 11 40 8 32 3 7 16...

output:

885189946

result:

ok 1 number(s): "885189946"

Subtask #4:

score: 10
Accepted

Test #4:

score: 10
Accepted
time: 56ms
memory: 2036kb

input:

100000
999998102 402961903 309346107 445160702 274308544 145846539 341002420 77841978 313436667 3206...

output:

714756233

result:

ok 1 number(s): "714756233"

Subtask #5:

score: 10
Accepted

Test #5:

score: 10
Accepted
time: 56ms
memory: 2040kb

input:

100000
999998479 400795186 127605328 439009686 279338791 222344190 32214702 347490239 390113609 1737...

output:

885251777

result:

ok 1 number(s): "885251777"

Subtask #6:

score: 10
Accepted

Test #6:

score: 10
Accepted
time: 53ms
memory: 2036kb

input:

100000
999980995 341927799 474797020 355936070 215296904 77682610 413850993 194378088 233473841 3566...

output:

99729538

result:

ok 1 number(s): "99729538"

Subtask #7:

score: 10
Accepted

Test #7:

score: 10
Accepted
time: 1ms
memory: 1276kb

input:

2000
540706819 309629779 17707890 194083691 334726587 456162964 498417390 246765617 957682339 604730...

output:

800177499

result:

ok 1 number(s): "800177499"

Subtask #8:

score: 10
Accepted

Test #8:

score: 10
Accepted
time: 0ms
memory: 1276kb

input:

2000
101722906 988313572 550840902 777765553 778991206 95817204 989809443 357040014 425595004 794587...

output:

443206431

result:

ok 1 number(s): "443206431"

Subtask #9:

score: 10
Accepted

Test #9:

score: 10
Accepted
time: 56ms
memory: 2036kb

input:

100000
327468559 836395032 98737045 14714567 147268924 355455125 829199457 117664948 79547712 117935...

output:

252529800

result:

ok 1 number(s): "252529800"

Subtask #10:

score: 10
Accepted

Test #10:

score: 10
Accepted
time: 48ms
memory: 2036kb

input:

100000
334373908 573410989 584461609 757523993 595819683 93095595 866600961 552146722 657326632 1804...

output:

633437866

result:

ok 1 number(s): "633437866"