QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#409#215742#21792. 【NOIP Round #6】抉择yzlliyelinFailed.2023-10-15 18:08:492023-10-15 18:08:49

詳細信息

Extra Test:

Accepted
time: 1ms
memory: 5752kb

input:

1
0

output:

0

result:

ok 1 number(s): "0"

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#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;
}