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:pascal 水 by yqk 感谢我吧 呵呵哈哈哈或或或或或

Posted by zhanglourui at 2017-08-05 14:45:13 on Problem 2201
In Reply To:pascal 水 by yqk 感谢我吧 呵呵哈哈哈或或或或或 Posted by:yangqikai at 2017-08-05 14:41:46
> var
>  n:longint;
>  a:array[0..50000,1..3]of longint;
>  f:array[0..16]of longint;
>  mi:array[0..50000,0..16,1..2]of longint;
>  o:array[0..50000,1..3]of longint;
> procedure init;
> var
>  i:longint;
> begin
>  f[0]:=1;
>  for i:=1 to 16 do 
>    f[i]:=f[i-1]*2;
>  read(n);
>  for i:=1 to n do
>   begin
>   readln(a[i,1],a[i,2]);
>   a[i,3]:=i;
>   end;
> end;
> procedure qsort(l,r:longint);
> var
>  i,j,k:longint;
> begin
>  if l>=r then exit;
>  i:=l;
>  j:=r;
>  k:=a[(l+r) div 2,1];
>  while i<j do
>   begin
>   while a[i,1]<k do inc(i);
>   while a[j,1]>k do dec(j);
>   if i<=j then
>    begin
>    a[0]:=a[i];
>    a[i]:=a[j];
>    a[j]:=a[0];
>    inc(i);
>    dec(j);
>    end;
>   end;
>  qsort(l,j);
>  qsort(i,r);
> end;
> procedure dfs(l,r:longint);
> var
>  i,t,ft,lt,rt,x:longint;
> begin
>  if r<=l then exit;
>  t:=trunc(ln(r-l+1)/ln(2));
>  if mi[l,t,1]<mi[r-f[t]+1,t,1] then x:=mi[l,t,2]
>                                else x:=mi[r-f[t]+1,t,2];
>  ft:=a[x,3];
>  lt:=0;
>  if l<>x then
>  begin
>  t:=trunc(ln(x-l)/ln(2));
>  if mi[l,t,1]<mi[x-f[t],t,1] then lt:=a[mi[l,t,2],3]
>                             else lt:=a[mi[x-f[t],t,2],3];
>  end;
>  rt:=0;
>  if r<>x then
>  begin
>  t:=trunc(ln(r-x)/ln(2));
>  if mi[x+1,t,1]<mi[r-f[t]+1,t,1] then rt:=a[mi[x+1,t,2],3]
>                                  else rt:=a[mi[r-f[t]+1,t,2],3];
>  end;
>  o[ft,2]:=lt;
>  o[ft,3]:=rt;
>  o[lt,1]:=ft;
>  o[rt,1]:=ft;
>  dfs(l,x-1);
>  dfs(x+1,r);
> end;
> procedure main;
> var
>  i,b,t:longint;
> begin
>  for i:=1 to n do mi[i,0,1]:=a[i,2];
>  for i:=1 to n do mi[i,0,2]:=i;
>  for t:=1 to trunc(ln(n)/ln(2)) do
>   for b:=1 to n-f[t]+1 do
>    if mi[b,t-1,1]>mi[b+f[t-1],t-1,1] then mi[b,t]:=mi[b+f[t-1],t-1]
>                                      else mi[b,t]:=mi[b,t-1];
>  dfs(1,n);
> end;
> procedure print;
> var
>  i:longint;
> begin
>  writeln('YES');
>  for i:=1 to n do
>   writeln(o[i,1],' ',o[i,2],' ',o[i,3]);
> end;
> begin
>  init;
>  qsort(1,n);
>  main;
>  print;
> 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