| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:pascal的注意了!!!不要开50w的数组存裸string,会mle,改成string【20】就能过了!!In Reply To:pascal的注意了!!!不要开50w的数组存裸string,会mle,改成string【20】就能过了!! Posted by:wukewen at 2014-03-10 23:11:19 渣代码
。。。。。。。。。。。。。。。。。。。。。。。。。
const
disprime:array[1..35] of longint=(1,2,4,6,12,24,36,48,60,120,180,240,360,720,840,1260,1680,2520,5040,7560,10080,15120,20160,25200,27720,45360,50400,55440,83160,110880,166320,221760,277200,332640
,498960);
divi:array[1..35] of longint=(1,2,3,4,6,8,9,10,12,16,18,20,24,30,32,36,40,48,60,64,72,80,84,90,96,100,108,120,128,144,160,168,180,192,200);
primes=35;
var
segment:array[0..2000000] of longint;
n,i,j,k,l,s,m,t,tt,ttt:longint;
st:string;
a,bit:array[0..500010] of longint;
b:array[0..500010] of string[20];
procedure build(x,l,r:longint);
var
mid:longint;
begin
segment[x]:=r-l+1;
if l=r then exit;
mid:=(l+r) shr 1;
build(x shl 1,l,mid);
build((x shl 1)+1,mid+1,r);
end;
procedure plus(x,sub:longint);
begin
while x<=n do
begin
inc(bit[x],sub);
x:=x+x and -x;
end;
end;
function getans(x,l,r,sub:longint):longint;
var
mid:longint;
begin
dec(segment[x]);
if l=r then exit(l);
mid:=(l+r) shr 1;
if segment[x shl 1]>=sub then exit(getans(x shl 1,l,mid,sub))
else exit(getans((x shl 1)+1,mid+1,r,sub-segment[x shl 1]));
end;
function tot(x:longint):longint;
begin
tot:=0;
while x>0 do
begin
inc(tot,bit[x]);
x:=x-x and -x;
end;
end;
function ans(x:longint):longint;
var
i:longint;
begin
for i:=1 to primes-1 do
if disprime[i]<=x then if disprime[i+1]>x then exit(i);
exit(primes);
end;
begin
while not eof do
begin
readln(n,m);
fillchar(bit,sizeof(bit),0);
for i:=1 to n do
begin
readln(st);
st:=st+' ';
j:=1;
while st[j]<>' ' do inc(j);
b[i]:=copy(st,1,j-1);
inc(j);
k:=j;
while st[j]<>' ' do inc(j);
val(copy(st,k,j-k),s);
a[i]:=s;
plus(i,1);
end;
build(1,1,n);
t:=getans(1,1,n,m);
plus(t,-1);
tt:=ans(n);
ttt:=divi[tt];
tt:=disprime[tt];
st:='';
if tt=1 then st:=b[t];
for i:=1 to n-2 do
if st<>'' then break
else
begin
j:=a[t];
s:=tot(t);
if j<0 then
begin
j:=-j;
j:=j mod (n-i);
if j=0 then j:=n-i;
if j<=s then j:=s-j+1
else j:=n-i-(j-s-1);
t:=getans(1,1,n,j);
end
else
begin
j:=(s+j) mod (n-i);
if j=0 then j:=n-i;
t:=getans(1,1,n,j);
end;
plus(t,-1);
if i+1=tt then st:=b[t];
end;
if st='' then
begin t:=getans(1,1,n,1); st:=b[t]; end;
writeln(st,' ',ttt);
end;
end.
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator