QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#409#215742#21792. 【NOIP Round #6】抉择yzlliyelinFailed.2023-10-15 18:08:492023-10-15 18:08:49

Details

Extra Test:

Accepted
time: 1ms
memory: 5752kb

input:

1
0

output:

0

result:

ok 1 number(s): "0"

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#215742#21792. 【NOIP Round #6】抉择liyelin100 ✓224ms19228kbC++14475b2023-10-15 13:19:462023-10-15 13:19:46

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const int B = 61;
typedef long long ll;
int n, p[B];
ll a[N], ans, f[N];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		f[i] = 0;
		for (int j = B - 1; j >= 0; j--) {
			f[i] = max(f[i], f[p[j]] + (a[p[j]] & a[i]));
			if ((a[i] >> j) & 1) p[j] = i;
		}
		ans = max(ans, f[i]);
	}
	cout << ans << endl;
	return 0;
}