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 wukewen at 2013-11-21 22:53:35 on Problem 1068
var
  a:array[0..100,1..3] of longint;
  n,i,j,k,l,s,x,m,sum:longint;
begin
  readln(n);
  for i:=1 to n do
    begin
    readln(m);
    fillchar(a,sizeof(a),0);
    sum:=0;
    for j:=1 to m do
      begin
      read(x);
      if (sum=0)or(x>a[sum,1]) then
         begin
         if j=1 then write(1)
            else write(' ',1);
         inc(sum);
         a[sum,1]:=x;
         a[sum,2]:=0;
         a[sum-1,2]:=x-a[sum-1,1]-1;
         a[sum,3]:=1;
         end
         else
         begin
         s:=0;
         while a[sum,2]=0 do
           begin
           inc(s,a[sum,3]);
           dec(sum);
           end;
         dec(a[sum,2]);
         inc(s);
         inc(sum);
         a[sum,1]:=x;
         a[sum,2]:=0;
         a[sum,3]:=s;
         write(' ',s);
         end;
      end;
    writeln;
    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