# [2018雅礼省选集训4-2]Problem A 位运算+势能分析线段树

#include<iostream>
#include<cstdio>
#include<cstring>
#define mid (l+r>>1)
#define N 200010
using namespace std;
const int R=(1<<20)-1;
int n,q,a[N];
{
int x=0,f=1;char ch=getchar();
for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=-1;
for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
return x*f;
}
struct tree
{
int mx,h,y,bh,by;
tree *ls,*rs;
tree(){h=0;y=R;}
void update()
{
mx=max(ls->mx,rs->mx);
bh=ls->bh|rs->bh;
by=ls->by&rs->by;
}
void cal(int dh,int dy)
{
mx=(mx&dy)|dh;bh=(bh&dy)|dh;by=(by&dy)|dh;
y=(y&dy);h=(h&dy)|dh;
}
void pushdown()
{
ls->cal(h,y);
rs->cal(h,y);
h=0;y=R;
}
void build(int l,int r)
{
if(l==r) {mx=bh=by=a[l];return ;}
(ls=new tree)->build(l,mid);
(rs=new tree)->build(mid+1,r);
update();
}
void mdf(int l,int r,int lx,int rx,int dh,int dy)
{
if(l==lx&&r==rx)
{
int t=(by|(R^bh));
if(((dh|t)==t)&&(((R^dy)|t)==t)) {cal(dh,dy);return ;}
}
pushdown();
if(rx<=mid) ls->mdf(l,mid,lx,rx,dh,dy);
else if(lx>mid) rs->mdf(mid+1,r,lx,rx,dh,dy);
else ls->mdf(l,mid,lx,mid,dh,dy),rs->mdf(mid+1,r,mid+1,rx,dh,dy);
update();
}
int qry(int l,int r,int lx,int rx)
{
if(l==lx&&r==rx) return mx;
pushdown();
if(rx<=mid) return ls->qry(l,mid,lx,rx);
if(lx>mid) return rs->qry(mid+1,r,lx,rx);
return max(ls->qry(l,mid,lx,mid),rs->qry(mid+1,r,mid+1,rx));
}
}*xtr;
int main()
{
}