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

Psacal居然比c++短

Posted by 623329235 at 2015-11-03 20:52:34 on Problem 3580
我偷懒只写了单旋
program poj3580;
const maxlongint=maxlongint>>1;
var
  l,r,m,ad,w,s:array[0..200010] of longint;
  f:array[0..200010] of boolean;
  i,j,ll,rr,t,tmp,root,n,mt,a,b,c,d:longint;
  task:string;
  rd:char;

procedure update(i:longint);
begin
  if i=0 then exit;
  ll:=l[i];
  rr:=r[i];
  s[i]:=s[ll]+s[rr]+1;
  m[i]:=w[i];
  if m[ll]<m[i]
    then m[i]:=m[ll];
  if m[rr]<m[i]
    then m[i]:=m[rr];
end;

procedure left(var i:longint);
begin
  j:=r[i];
  r[i]:=l[j];
  l[j]:=i;
  update(i);
  update(j);
  i:=j;
end;

procedure right(var i:longint);
begin
  j:=l[i];
  l[i]:=r[j];
  r[j]:=i;
  update(i);
  update(j);
  i:=j;
end;

procedure put(var i,j:longint;k:boolean);
begin
  if i=0 then exit;
  if k then
  begin
    tmp:=l[i];
    l[i]:=r[i];
    r[i]:=tmp;
  end;
  f[i]:=f[i] xor k;
  inc(w[i],j);
  inc(ad[i],j);
  inc(m[i],j);//!
end;

procedure find(var i:longint;p:longint);
begin
  put(l[i],ad[i],f[i]);
  put(r[i],ad[i],f[i]);
  ad[i]:=0;
  f[i]:=false; //!
  if p<=s[l[i]] then
  begin
    find(l[i],p);
    right(i);
  end
  else
  if p=s[l[i]]+1
    then exit
    else
    begin
    find(r[i],p-s[l[i]]-1); left(i);
    end;
end;

begin
  readln(n);
  t:=n; m[0]:=maxlongint;
  root:=n+2; t:=root;//!
  i:=1; w[1]:=maxlongint; update(i);
  for i:=2 to n+1 do
  begin
    readln(w[i]);
    l[i]:=i-1;
    update(i);
  end;
  w[root]:=maxlongint;
  l[root]:=i;
  update(root);
  readln(mt);
  for mt:=1 to mt do
  begin
    task:='';rd:='!';
    while rd<>' ' do
    begin
      task:=task+rd;read(rd);
    end;
    if task='!ADD' then
    begin
      readln(a,b,c);
      b:=b+2;
      find(root,a);
      find(root,b);
      put(r[l[root]],c,false);
      update(l[root]);
      update(root);
    end else
    if task='!REVERSE' then
    begin
      readln(a,b);
      b:=b+2;
      c:=0;
      find(root,a);
      find(root,b);
      put(r[l[root]],c,true);
    end else
    if task='!REVOLVE' then
    begin
      readln(a,b,c);
      while c<0 do c:=c+b-a+1;
      c:=b-c mod (b-a+1)+1;
      b:=b+2;
      find(root,c);
      find(l[root],a);
      find(r[root],b-c);
      a:=r[l[root]];
      b:=l[r[root]];
      c:=l[root];
      r[c]:=b;
      l[root]:=a;
      l[r[root]]:=0;
      update(c);
      update(r[root]);
      update(root);
      find(root,1);
      l[root]:=c;
      update(root);
    end else
    if task='!INSERT' then
    begin
      readln(a,b);
      find(root,a+1);//!
      inc(t);
      r[t]:=r[root];
      r[root]:=t;
      w[t]:=b;
      update(t);
      update(root);
    end else
    if task='!DELETE' then
    begin
      readln(a);inc(a);
      find(root,a);
      find(r[root],1);
      l[r[root]]:=l[root];
      root:=r[root];
      update(root);
    end else begin
      readln(a,b);
      b:=b+2;
      find(root,a);
      find(root,b);
      writeln(m[r[l[root]]]);
    end;
  end;
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