线段树维护区间&
#include<bits/stdc++.h>
using namespace std;
int n,k,ans1,ans,a[1000010];
struct TREE{int l,r,w;}tree[4000010];
int read()
{
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
void pushup(int k)
{ tree[k].w=tree[k<<1].w&tree[k<<1|1].w; }
void build(int k,int l,int r)
{
tree[k].l=l;
tree[k].r=r;
if(l==r)
{
tree[k].w=a[l];
return;
}
int mid=l+r>>1;
build(k<<1,l,mid);
build(k<<1|1,mid+1,r);
pushup(k);
}
int query(int k,int x,int y)
{
int l=tree[k].l;
int r=tree[k].r;
if(x<=l&&r<=y) return tree[k].w;
int mid=l+r>>1,res=0x7fffffff;
if(x<=mid) res&=query(k<<1,x,y);
if(y>mid) res&=query(k<<1|1,x,y);
return res;
}
signed main()
{
n=read(),k=read();
for(int i=1;i<=n;i++)
{
a[i]=read();
ans1|=a[i];
}
build(1,1,n);
printf("%d ",ans1);
for(int i=1;i<=n-k+1;i++)
ans=max(ans,query(1,i,i+k-1));
printf("%d",ans);
return 0;
}