//https://codeforces.com/group/MKpYqfAQQQ/contest/401639/problem/D
#include<bits/stdc++.h>
#include<unordered_map>
#include<array>
#define ll long long
#define ull unsigned long long
#define all(a) a.begin(),a.end()
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
const ll mod = 998244353;
const int N = 1e6 + 5;
ll n, a[N], last[60], dp[N];
void solve()
{
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
{
for (int j = 0; j < 60; j++)
dp[i] = max(dp[i], dp[last[j]] + (a[last[j]] & a[i]));
for (int j = 0; j < 60; j++)
if (a[i] & (1ll << j))
last[j] = i;
}
ll ans = 0;
for (int i = 1; i <= n; i++)
ans = max(ans, dp[i]);
cout << ans << '\n';
}
signed main()
{
IOS;
int t = 1;
//cin >> t;
while (t--)
solve();
return 0;
}
Bank Security Unification(位运算优化dp),dp15
最新推荐文章于 2024-09-11 09:33:21 发布