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

PASCAL 1AC

Posted by aiouniya at 2012-08-29 15:00:51 on Problem 3067
var
 t,n,m,k,jj:longint;
 s:int64;
 a:array[0..1000010,1..2]of longint;
 c:array[1..1010]of longint;
 mark:array[1..1010]of boolean;
procedure qsort(l,r:longint);
var
 i,j,k1,k2:longint;
begin
 if l>=r then exit;
 i:=l;
 j:=r;
 k1:=a[(i+j) div 2,1];
 k2:=a[(i+j) div 2,2];
 while i<=j do
  begin
  while (a[i,2]>k2)or((a[i,2]=k2)and(a[i,1]>k1)) do inc(i);
  while (a[j,2]<k2)or((a[j,2]=k2)and(a[j,1]<k1)) 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;
function find(i:longint):longint;
begin
 find:=0;
 while i>0 do
  begin
  find:=find+c[i];
  i:=i-i and -i;
  end;
end;
procedure add(i:longint);
begin
 while i<=n do
  begin
  inc(c[i]);
  i:=i+i and -i;
  end;
end;
procedure main;
var
 i,j,o:longint;
begin
 qsort(1,k);
 for i:=1 to k do
  begin
    o:=find(a[i,1]-1);
    s:=s+o;
    add(a[i,1]);
  end;
end;
procedure print;
begin
 write('Test case ');
 write(jj);
 write(': ');
 write(s);
 writeln;
end;
procedure init;
var
 i:longint;
begin
 readln(t);
 for jj:=1 to t do
  begin
  s:=0;
  fillchar(a,sizeof(a),0);
  fillchar(c,sizeof(c),0);
  fillchar(mark,sizeof(mark),0);
  readln(n,m,k);
  for i:=1 to k do read(a[i,1],a[i,2]);
  main;
  print;
  end;
end;
begin
 init;
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