原題:
http://172.16.0.132/senior/#contest/show/2050/2
題目描述:
Abathur采集了一系列Primal Zerg 的基因樣本奥务,這些基因構(gòu)成了一個完整的進化鏈交掏。為了方便指蚜,我們用A0,A1...An-1 這n 個正整數(shù)描述它們。
一個基因Ax 可以進化為序列中在它之后的基因Ay。這個進化的復雜度婆芦,等于Ax | Ax+1...| Ay的值,其中| 是二進制或運算。
Abathur 認為復雜度小于M 的進化的被認為是溫和的倍宾。它希望計算出溫和的進化的對數(shù)。
輸入:
第一行包含兩個整數(shù)n,m胜嗓。
接下來一行包含A0,A1...An-1 這n 個正整數(shù)高职,描述這n 個基因。
輸出:
第一行包含一個整數(shù)辞州,表示溫和的進化的對數(shù)怔锌。
樣例輸入:
4 6
1 3 5 1
樣例輸出:
2
數(shù)據(jù)范圍限制:
對于30% 的數(shù)據(jù),1 <= n <=1000。
對于100% 的數(shù)據(jù)埃元,1 <= n<= 100000涝涤,0 <= m <= 2^30,1<= Ai<= 2^30岛杀。
分析:
前綴和+暴力枚舉+優(yōu)化
優(yōu)化:由于數(shù)據(jù)太大阔拳,我們可以跳著做,當發(fā)現(xiàn)跳到的點不符合要求类嗤,那么返回上一個點糊肠,從這個點開始一個一個找,ans+=(r-l+1);
實現(xiàn):
var
ans,p:int64;
n,m,i,j,t,l:longint;
a,s:array[1..100000]of int64;
procedure w;
begin
for i:=1 to n do
begin
p:=0;
t:=i;
if i+100<=n then
while true do
begin
if p or s[t]>m then break;
p:=p or s[t];
t:=t+101;
if t+100>n then break;
end;
if t>i then ans:=ans+t-1-i;
l:=0;
for j:=t to n do
begin
if p or a[j]>m then break;
inc(l);
p:=p or a[j];
end;
if l>0 then
if t=i then ans:=ans+l-1
else ans:=ans+l;
end;
end;
begin
assign(input,'evolve.in');reset(input);
assign(output,'evolve.out');rewrite(output);
readln(n,m);
for i:=1 to n do read(a[i]);
s:=a;
for i:=1 to n do
for j:=i+1 to i+100 do s[i]:=s[i] or a[j];
w;
writeln(ans);
end.