QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#920#593490#21792. 【NOIP Round #6】抉择houpingzehoupingzeFailed.2024-09-27 14:24:292024-09-27 14:24:32

详细

Extra Test:

Accepted
time: 1ms
memory: 5848kb

input:

5
4 2 3 1 5

output:

4

result:

ok 1 number(s): "4"

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#593490#21792. 【NOIP Round #6】抉择houpingze100 ✓266ms20500kbC++14589b2024-09-27 14:20:412024-09-27 14:20:42

answer

#include<bits/stdc++.h>
#define int long long
#define rep(i,x,y) for(int i=x;i<=y;i++)
using namespace std;
int n;
int a[1145141];
int f[1000050];
int lst[1145];
signed main(){
	cin>>n;
	rep(i,1,n) {
		scanf("%lld",&a[i]);
	}
	f[1]=0;
	f[2]=(a[1]&a[2]);
	rep(i,1,2){
		
		rep(j,0,50){
			if(a[i]&(1ll<<j)){
				lst[j]=i;
			}
		}
	}
	for(int i=3;i<=n;i++){
		rep(j,0,50){
			f[i]=max(f[i],f[lst[j]]+(a[lst[j]]&a[i]));
		}
		rep(j,0,50){
			if(a[i]&(1ll<<j)){
				lst[j]=i;
			}
		}
	}
	int ans=0;
	rep(i,1,n) ans=max(ans,f[i]);
	cout<<ans;
	return 0;
}