注意2e6<2^21
从大到小枚举ai
对于每个ai 用递归找到ai前所有数能&出的值
用cnt记录每个数以及它的1位子集出现的次数
对于ai为0的每一位从高位到低位贪心
#include<bits/stdc++.h>
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define for1(I, A, B) for (int I = (A); I < (B); ++I)
#define forn(I, A, B) for (int I = (A); I <= (B); ++I)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef set<int> si;
typedef double db;
const db eps=1e-8;
const db pi=acos(-1);
const ll inf=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const int MAX=4e6+10;
const ll mod=1e9+7;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int vis[MAX],cnt[MAX],a[MAX];
void add(int a,int b)
{
if(cnt[a]>1||vis[a]==b)return;
cnt[a]++;
vis[a]=b;
forn(i,0,21)
{
int t=(1<<22)-1-(1<<i);
add(a&t,b);
}
}
void pb(int x)
{
vi v;
while(x!=0)
{
v.push_back(x%2);
x/=2;
}
for(auto x=v.rbegin();x!=v.rend();x++)
{
cout<<*x;
}
cout<<endl;
}
int ans;
int main(){
IO;
int n;
cin>>n;
forn(i,1,n)cin>>a[i];
add(a[n],n);add(a[n-1],n-1);
for(int i=n-2;i>=1;i--)
{
int tmp=0;
int rev=(1<<(22))-1-a[i];
// pb(rev);
for(int j=21;j>=0;j--)
{
int t=(1<<21)-1-(1<<j);
if(((a[i]|t)!=(1<<21)-1)&&cnt[tmp|(1<<j)]>1)
{
tmp|=(1<<j);
}
}
ans=max(ans,a[i]|tmp);
add(a[i],i);
}
cout<<ans<<endl;
}