Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我也不知道是什么算法。。。

Posted by SodaLi at 2012-09-20 14:41:08 on Problem 3368
瞎做的。。
program p3368;
type    mytype=record
            ans,f,b,len1,len2:longint;
        end;
var     e,w,i,lev,n,q:longint;
        a:array[1..100000] of longint;
        f:array[1..100000,0..18] of mytype;
function find(q:longint):longint;
begin
    find:=-1;
    while q>0 do begin
        inc(find);
        q:=q div 2;
    end;
end;
function max(a,b:longint):longint;
begin
    if a>b then exit(a)
    else exit(b);
end;
function con(q,w:mytype):mytype;
begin
    con.ans:=max(q.ans,w.ans);
    if q.b=w.f then
        con.ans:=max(con.ans,q.len2+w.len1);
    con.f:=q.f;
    con.b:=w.b;
    if q.f=w.f then con.len1:=q.len1+w.len1
    else con.len1:=q.len1;
    if q.b=w.b then con.len2:=q.len2+w.len2
    else con.len2:=w.len2;
end;
procedure que(q,w:longint);
var     i,len,lev:longint;
        ans:mytype;
begin
    lev:=find(w);
    len:=1;
    for i:=1 to lev do
        len:=len*2;
    ans:=f[q,lev];
    inc(q,len);
    dec(w,len);
    while w>0 do begin
        dec(lev);
        len:=len div 2;
        if w>=len then begin
            ans:=con(ans,f[q,lev]);
            inc(q,len);
            dec(w,len);
        end;
    end;
    writeln(ans.ans);
end;
procedure prepare;
var     i,j,len:longint;
begin
    for i:=1 to n do begin
        f[i,0].ans:=1;
        f[i,0].f:=a[i];
        f[i,0].b:=a[i];
        f[i,0].len1:=1;
        f[i,0].len2:=1;
    end;
    len:=1;
    for i:=1 to lev do begin
        len:=len*2;
        for j:=1 to n-len+1 do
            f[j,i]:=con(f[j,i-1],f[j+(len div 2),i-1]);
    end;
end;
procedure init;
var     i:longint;
begin
    fillchar(a,sizeof(a),0);
    for i:=1 to n do
        read(a[i]);
end;
begin
    repeat
        read(n);
        if n<>0 then begin
            readln(q);
            init;
            lev:=find(n);
            prepare;
            for i:=1 to q do begin
                readln(e,w);
                que(e,w-e+1);
            end;
        end;
    until n=0;
end.

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator