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:哪位大牛能看一下我的这个程序为什么会Runtime Error !!! 感激不尽 !!!!!In Reply To:Re:哪位大牛能看一下我的这个程序为什么会Runtime Error !!! 感激不尽 !!!!! Posted by:DMKaplony at 2010-04-16 08:38:42 > 同RE... 我也re啊,郁闷! var i,j,k,si,l,r,l2,r2,n,q,ce,cei:longint; er:array[0..30]of longint; a,b,s,jl,jr:array[0..200000] of longint; f:array[0..200000,0..30] of longint; function max(a,b:longint):longint; begin if a>b then exit(a) else exit(b); end; procedure rmq; var i,j,k:longint; begin for i:=1 to n do f[i,0]:=s[i]; for j:=1 to trunc(ln(n)/ln(2))+1 do for i:=1 to n do begin if i+er[j]-1>n then continue; f[i,j]:=max(f[i,j-1],f[i+er[j-1],j-1]) end; end; function qujian(i,j:longint):longint; var k:longint; begin if i>j then exit(0); k:=i-j+1; if k<>0 then k:=trunc(ln(k)/ln(2)); exit(max(f[i,k],f[j-er[k]+1,k])); end; begin while true do begin read(n); if n=0 then exit; readln(q); er[0]:=1; for i:=1 to 30 do er[i]:=er[i-1]*2 ; for i:=1 to n do begin read(a[i]); end; i:=1; si:=0; while true do begin k:=1; for j:=i+1 to n do begin if a[j]<>a[j-1] then break else inc(k); end; inc(si); s[si]:=k; for j:=i to i+k-1 do begin b[j]:=si; jl[j]:=j-i; jr[j]:=i+k-1-j; end; i:=i+k; if i>n then break; end; rmq; for i:=1 to q do begin readln(l,r) ; if b[l]=b[r] then begin writeln(r-l+1); continue; end; l2:=l+jr[l]+1; r2:=r-jl[r]-1; writeln(max(max(qujian(b[l2],b[r2]),jr[l]+1),jl[r]+1)) end; end; end. Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator