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

RE+WA好几天了,求大神伸出援手

Posted by lxm2010 at 2013-03-01 20:40:37 on Problem 3580
program aa;
var
  a,mins,data,add_x:array[-1..400010] of int64;
  rev:array[-1..400010] of boolean;
  next,left,right,size:array[-1..400010] of longint;
  n,m,i,head,maxc,root,st,wt,y,st2,root_n,temp,t:longint;
  add_data:int64;
  ch,ch2:char;
function min(a,b:int64):int64;
begin
  if a<b then min:=a
  else min:=b;
end;
procedure modify(x:longint);
begin
  if x=0 then exit;
  mins[x]:=min(data[x],min(mins[left[x]],mins[right[x]]));
  size[x]:=size[left[x]]+size[right[x]]+1;
end;
function left_rotate(root:longint):longint;
var
  y:longint;
begin
  y:=right[root];
  right[root]:=left[y];
  modify(root);
  left[y]:=root;
  modify(y);
  exit(y);
end;
function right_rotate(root:longint):longint;
var
  y:longint;
begin
  y:=left[root];
  left[root]:=right[y];
  modify(root);
  right[y]:=root;
  modify(y);
  exit(y);
end;
procedure pushdown(root:longint;k:int64);
var
  y:longint;
begin
  if root=0 then exit;
  if k>0 then
  begin
    add_x[root]:=add_x[root]+k;
    data[root]:=data[root]+k;
    mins[root]:=mins[root]+k;
  end;
end;
procedure deal(root:longint;bo:boolean);
var
  t:longint;
begin
  if root=0 then exit;
  if bo then
  begin
    t:=left[root];
    left[root]:=right[root];
    right[root]:=t;
    rev[root]:=not rev[root];
  end;
end;
function splay(root,k:longint):longint;
var
  x:longint;
begin
  deal(left[root],rev[root]);
  deal(right[root],rev[root]);
  pushdown(left[root],add_x[root]);
  pushdown(right[root],add_x[root]);
  add_x[root]:=0;
  rev[root]:=false;
  x:=size[left[root]]+1;
  if x=k then splay:=root
  else if x<k then
  begin
    right[root]:=splay(right[root],k-x);
    exit(left_rotate(root));
  end
  else
  begin
    left[root]:=splay(left[root],k);
    exit(right_rotate(root));
  end;
end;
procedure build;
begin
  data[-1]:=maxlongint;
  data[1]:=a[1];
  mins[1]:=a[1];
  size[1]:=1;
  right[-1]:=1;
  for i:=2 to n do
  begin
    data[i]:=a[i];
    mins[i]:=a[i];
    size[i]:=1;
    right[i-1]:=i;
  end;
  data[n+1]:=maxlongint;
  mins[n+1]:=maxlongint;
  size[n+1]:=1;
  right[n]:=n+1;
  for i:=n downto 1 do
    modify(i);
  modify(-1);
end;
procedure init;
begin
  fillchar(rev,sizeof(rev),false);
  fillchar(left,sizeof(left),0);
  fillchar(right,sizeof(right),0);
  fillchar(mins,sizeof(mins),0);
  fillchar(size,sizeof(size),0);
  fillchar(add_x,sizeof(add_x),0);
  data[0]:=maxlongint;
  mins[0]:=maxlongint;
  root:=-1;
  readln(n);
  for i:=1 to n do
    readln(a[i]);
  build;
  readln(m);
  head:=n+2;
  maxc:=400001;
  for i:=head to maxc do
    next[i]:=i+1;
end;
procedure main;
begin
  for i:=1 to m do
  begin
    read(ch);
    case ch of
      'A':
      begin
        while ch<>' ' do read(ch);
        readln(st,wt,add_data);
        root:=splay(root,wt+2);
        root:=splay(root,st);
        pushdown(left[right[root]],add_data);
        modify(right[root]);
        modify(root);
      end;
      'I':
      begin
        while ch<>' ' do read(ch);
        readln(st,add_data);
        root:=splay(root,st+2);
        root:=splay(root,st+1);
        y:=right[root];
        data[head]:=add_data;
        right[root]:=head;
        right[head]:=y;
        modify(head);
        head:=next[head];
        modify(root);
      end;
      'D':
      begin
        while ch<>' ' do read(ch);
        readln(st);
        root:=splay(root,st+2);
        root:=splay(root,st);
        left[right[root]]:=0;
        modify(right[root]);
        modify(root);
        next[st]:=head;
        head:=st;
      end;
      'M':
      begin
        while ch<>' ' do read(ch);
        readln(st,wt);
        root:=splay(root,wt+2);
        root:=splay(root,st);
        writeln(mins[left[right[root]]]);
      end;
      'R':
      begin
        read(ch2,ch2,ch2);
        if ch2='E' then
        begin
          while ch2<>' ' do read(ch2);
          readln(st,wt);
          root:=splay(root,wt+2);
          root:=splay(root,st);
          deal(left[right[root]],true);
        end
        else if ch2='O' then
        begin
          while ch2<>' ' do read(ch2);
          readln(st,wt,t);
          while t<0 do t:=t+wt-st+1;
          t:=t mod (wt-st+1);
          st2:=wt-t;
          if t<>0 then
          begin
            root:=splay(root,wt+2);
            root:=splay(root,st);
            left[right[root]]:=splay(left[right[root]],st2+2-st);
            left[right[root]]:=splay(left[right[root]],wt-st+1);
            root_n:=left[right[root]];
            temp:=left[root_n];
            right[root_n]:=left[temp];
            left[temp]:=0;
            modify(temp);
            modify(root_n);
          end;
        end;
      end;
    end;
  end;
end;
begin
  init;
  main;
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