Code Forces 1030E
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Code Forces 1030E相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/span' title='span'>span
class sum pre 娌℃湁 杩涘埗 鎬濊矾 array 鍏虫敞棰樼洰澶ф剰锛?/h1>
缁欎綘n涓暟锛屼綘鍙互浜ゆ崲涓€涓暟鐨勪换鎰忎簩杩涘埗浣嶏紝闂綘鍙互閫夊嚭澶氬皯鍖洪棿缁忚繃鎿嶄綔鍚庡紓鎴栧拰鏄?銆?/p>
鎬濊矾鍒嗘瀽锛?/h1>
鏍规嵁棰樼洰锛屽緢瀹规槗鐭ラ亾锛屽浜庢瘡涓暟锛屾垜浠彲浠ユ棤瑙嗗畠鐨?鍦ㄩ偅浜涗綅缃紝鍙鍏虫敞瀹冩湁鍑犱釜1鍗冲彲锛屽鏋滃畠鐨?鐨勬暟閲忓彲浠ラ€氳繃鍔犲噺涓?锛岄偅涔堣繖涓尯闂村氨鏄悎娉曠殑銆?/p>
鍙互鐪嬪埌锛屼袱涓暟锛堝垎鍒湁x锛寉涓?锛屼笖x銆墆锛夐€氳繃浜ゆ崲浣嶇疆鍐嶈繘琛屽紓鎴栨搷浣滐紝鍙兘鑾峰緱鐨勬柊鏁颁腑1鐨勬暟閲忎负y-x锛寉-x+2锛寉-x+4锛?..锛寈+y-2锛寈+y銆?/p>
閭d箞瀵逛簬姣忎竴涓乏绔偣锛坙锛夛紝瀹冪殑鍚堟硶鍙崇鐐癸紙r锛夌殑鏁伴噺涓簊um[r]-sum[l-1]涓哄伓鏁扮殑r鐨勪釜鏁帮紙sum涓哄墠缂€鍜屾暟缁勶級銆傚悓鏃讹紝杩欎釜鍖洪棿杩樿婊¤冻鍖洪棿鍐?鐨勬暟閲忔渶澶氱殑鏁帮紙鍋囪瀹冨湪绗琸浣嶏級瑕佸皬浜巗um[k]-sum[l-1]鐨勪竴鍗婏紝鍥犱负鍋囧璇村畠涓嶆弧瓒宠繖涓€鏉′欢鐨勮瘽锛岄偅涔堝氨娌℃湁瓒冲澶氱殑1鍚屽畠鐩告姷娑堬紝涔熷氨涓嶄細鍚堟硶銆?/p>
閭d箞鎴戜滑搴旇濡備綍閬垮厤杩欑鐘跺喌鍛紵
寰堢畝鍗曪紝鍙兘浼氭槸涓嶅悎娉曞彸绔偣鐨勫嚑涓偣锛堟渶澶?4涓級鐩存帴鏆村姏鍋氬氨琛屼簡銆?/p>
浠g爜锛?/h1>
var
a,sum,odd,even:array[0..300000]of longint;
i,j,s,max,n,m:longint;
ans,x:int64;
begin
read(n);
for i:=1 to n do
begin
read(x);
while x>0 do
begin
a[i]:=a[i]+x and 1;
x:=x>>1;
end;
end;
for i:=1 to n do
begin
sum[i]:=sum[i-1]+a[i];
odd[i]:=odd[i-1]; even[i]:=even[i-1];
if sum[i]and 1=1 then inc(odd[i]) else inc(even[i]);
end;
for i:=1 to n do
if sum[i-1]and 1=1 then ans:=ans+odd[n]-odd[i-1]
else ans:=ans+even[n]-even[i-1];
writeln(ans);
for i:=1 to n do
begin
if i+64>n then m:=n else m:=i+64;
s:=0; max:=0;
for j:=i to m do
begin
if a[j]>max then max:=a[j];
s:=s+a[j];
if (2*max>s)and(s mod 2=0) then dec(ans);
end;
end;
writeln(ans);
end.
var a,sum,odd,even:array[0..300000]of longint; i,j,s,max,n,m:longint; ans,x:int64; begin read(n); for i:=1 to n do begin read(x); while x>0 do begin a[i]:=a[i]+x and 1; x:=x>>1; end; end; for i:=1 to n do begin sum[i]:=sum[i-1]+a[i]; odd[i]:=odd[i-1]; even[i]:=even[i-1]; if sum[i]and 1=1 then inc(odd[i]) else inc(even[i]); end; for i:=1 to n do if sum[i-1]and 1=1 then ans:=ans+odd[n]-odd[i-1] else ans:=ans+even[n]-even[i-1]; writeln(ans); for i:=1 to n do begin if i+64>n then m:=n else m:=i+64; s:=0; max:=0; for j:=i to m do begin if a[j]>max then max:=a[j]; s:=s+a[j]; if (2*max>s)and(s mod 2=0) then dec(ans); end; end; writeln(ans); end.
以上是关于Code Forces 1030E的主要内容,如果未能解决你的问题,请参考以下文章