[r]
(1)Bài 81/2001 - Dãy nghịch thế (Dành cho học sinh PTTH) Program day_nghich_the; uses crt;
const fn = 'nghich.inp'; gn = 'nghich.out'; nmax=10000; var f,g:text;
n,i,j,dem:0 nmax;
a,b,luu:array[1 nmax] of nmax; procedure nhap;
begin
fillchar(a,sizeof(a),0); b:=a; assign(f,fn); reset(f); readln(f,n);
for i:=1 to n read(f,a[i]); write(f); for i:=1 to n read(f,b[i]);
close(f); end;
procedure tim_b; begin
fillchar(luu,sizeof(luu),0); for i:=1 to n
begin dem:=0;
for j:=i -1 downto if a[i]<a[j] then inc(dem); luu[a[i]]:=dem;
end;
for i:=1 to n write(g,luu[i]:2); writeln(g); writeln(g);
end;
procedure tim_a; begin
fillchar(luu,sizeof(luu),0); for i:=1 to n
if b[i]>n-i then exit else begin
j:=0; dem:=0; repeat inc(dem);
if luu[dem]=0 then j:=j+1; until j>b[i];
(2)for i:=1 to n write(g,luu[i]:2); end;
BEGIN nhap;
assign(g,gn);rewrite(g); tim_b;
tim_a; close(g); END