输入
输出
输入样例复制
input 1:
6 3
1 1 1 0 0 0
input 2:
6 3
1 1 0 1 0 0
input 3:
6 3
11 8 2 1 3 9
输出样例复制
output 1
1 1
output 2
1 0
output 3
11 1
说明
题解:认真审题 连续子序列
对于or,显然or的数越多越大,所以整个序列or在一起就是答案
对于and,将每个数字转为二进制,对于每一位,若前面包括自己有>=k个连续的1,则该位可为1
例子,当k=2
110010
011101
101110
最终 110010 110010
011101 011101
101110 101110 16 12
选前两个
const
inf='1230.in';
ouf='1230_2.out';
maxn=1000000;
var
a,f:array[0..maxn,0..33]of longint;
val:array[0..33]of longint;
n,k,ymw,ans1,ans2,sum:longint;
i,j:longint;
function max(a,b:int64):longint;
begin
if a>b then exit(a) else exit(b);
end;
procedure init;
var
i,j:longint;
x:int64;
begin
readln(n,k);val[1]:=1;
for i:=2 to 33 do
val[i]:=val[i-1]*2;
for i:=1 to n do
begin
read(x);
ans1:=ans1 or x;
while x>0 do
begin
inc(f[i,0]);
f[i,f[i,0]]:=x mod 2;
x:=x div 2;
end;
ymw:=max(ymw,f[i,0]);
end;
for i:=1 to n do
for j:=1 to ymw do
if f[i,j]<>0 then f[i,j]:=f[i-1,j]+1;
end;
begin
// assign(input,inf);reset(input);
// assign(output,ouf);rewrite(output);
init;
for i:=k to n do
begin
sum:=0;
for j:=1 to ymw do
if f[i,j]>=k then sum:=sum+val[j];
ans2:=max(ans2,sum);
end;
writeln(ans1,' ',ans2);
//close(input);close(output);
end.