- 小白逛公园
- 2013-03-26 21:24:03 @
program p1083;
type
point=^tree;
tree=record
n,m:point;
l,r,c:longint;
end;
var
t:point;
i,j,k,l,x,y,a,r:longint;
b:array[1..100000] of longint;
procedure maketree(var t:point);
begin
t^.c:=0;
if t^.l<t^.r then begin
l:=(t^.l+t^.r) div 2;
new(t^.n);new(t^.m);
t^.n^.l:=t^.l;t^.n^.r:=l;
t^.m^.l:=l+1;t^.m^.r:=t^.r;
maketree(t^.n);maketree(t^.m);
end;
end;
procedure jia(var t:point;i,k:longint);
var
m:longint;
begin
if t^.l<t^.r then begin
m:=(t^.l+t^.r) div 2;
if m<i then jia(t^.m,i,k)
else jia(t^.n,i,k);
end else
t^.c:=k;
end;
procedure bc(var t:point);
begin
if t^.l+1<t^.r then begin
bc(t^.n);bc(t^.m);
end;
if t^.l<t^.r then
if t^.n^.c<t^.m^.c then t^.c:=t^.m^.c
else t^.c:=t^.n^.c;
end;
procedure print(t:point;l,r:longint);
var
m:longint;
begin
if (t^.l>=l) and (t^.r<=r) then
if t^.c>a then a:=t^.c
else
else begin
m:=(t^.l+t^.r) div 2;
if (r<=m) then print(t^.n,l,r);
if (l>m) then print(t^.m,l,r);
if (l<=m) and (r>m) then begin
print(t^.n,l,m);
print(t^.m,m+1,r);
end;
end;
end;
procedure gai(var t:point;l,k:longint);
var
m:longint;
begin
m:=(t^.l+t^.r) div 2;
if t^.l<t^.r then begin
if l<=m then gai(t^.n,l,k);
if l>m then gai(t^.m,l,k);
if t^.n^.c<t^.m^.c then t^.c:=t^.m^.c
else t^.c:=t^.n^.c;
end else t^.c:=k;
end;
begin
readln(x,y);
new(t);
t^.l:=1;t^.r:=x;
maketree(t);
for i:=1 to x do begin
read(k);
jia(t,i,k);
end;
readln;
bc(t);
for i:=1 to y do begin
readln(j,k,l);
if j=1 then begin
print(t,k,l);
inc(r);
b[r]:=a;
a:=-1*maxlongint+1;
end;
if j=2 then gai(t,k,l);
end;
for i:=1 to r do
write(b[i],' ');
end.
自己打了一个随机数据生成器,没运行错误,这是什么状况
4 条评论
-
spg417 LV 5 @ 2013-03-28 15:14:40
program p1083;
type
point=^tree;
tree=record
n,m:point;
l,r,c:longint;
end;
var
t:point;
i,j,k,l,x,y,a,r:longint;
b:array[1..100000] of longint;
procedure maketree(var t:point);
begin
t^.c:=0;
if t^.l<t^.r then begin
l:=(t^.l+t^.r) div 2;
new(t^.n);new(t^.m);
t^.n^.l:=t^.l;t^.n^.r:=l;
t^.m^.l:=l+1;t^.m^.r:=t^.r;
maketree(t^.n);maketree(t^.m);
end;
end;
procedure jia(var t:point;i,k:longint);
var
m:longint;
begin
if t^.l<t^.r then begin
m:=(t^.l+t^.r) div 2;
if m<i then jia(t^.m,i,k)
else jia(t^.n,i,k);
end else
t^.c:=k;
end;
procedure bc(var t:point);
begin
if t^.l+1<t^.r then begin
bc(t^.n);bc(t^.m);
end;
if t^.l<t^.r then
if t^.n^.c<t^.m^.c then t^.c:=t^.m^.c
else t^.c:=t^.n^.c;
end;
procedure print(t:point;l,r:longint);
var
m:longint;
begin
if (t^.l>=l) and (t^.r<=r) then
if t^.c>a then a:=t^.c
else
else begin
m:=(t^.l+t^.r) div 2;
if (r<=m) then print(t^.n,l,r);
if (l>m) then print(t^.m,l,r);
if (l<=m) and (r>m) then begin
print(t^.n,l,m);
print(t^.m,m+1,r);
end;
end;
end;
procedure gai(var t:point;l,k:longint);
var
m:longint;
begin
m:=(t^.l+t^.r) div 2;
if t^.l<t^.r then begin
if l<=m then gai(t^.n,l,k);
if l>m then gai(t^.m,l,k);
if t^.n^.c<t^.m^.c then t^.c:=t^.m^.c
else t^.c:=t^.n^.c;
end else t^.c:=k;
end;
begin
readln(x,y);
new(t);
t^.l:=1;t^.r:=x;
maketree(t);
for i:=1 to x do begin
read(k);
jia(t,i,k);
end;
readln;
bc(t);
for i:=1 to y do begin
readln(j,k,l);
if j=1 then begin
print(t,k,l);
inc(r);
b[r]:=a;
a:=-1*maxlongint+1;
end;
if j=2 then gai(t,k,l);
end;
for i:=1 to r do
write(b[i],' ');
end. -
2013-03-26 21:42:04@
参见编辑器快速入门。
简单描述即在代码块每行前加一个tab或者四个空格 -
2013-03-26 21:37:16@
补一句,求大神教怎么缩进
-
2013-03-26 21:35:15@
program p1083;
type
point=^tree;
tree=record
n,m:point;
l,r,c:longint;
end;
var
t:point;
i,j,k,l,x,y,a,r:longint;
b:array[1..100000] of longint;
procedure maketree(var t:point);
begin
t^.c:=0;
if t^.l<t^.r then begin
l:=(t^.l+t^.r) div 2;
new(t^.n);new(t^.m);
t^.n^.l:=t^.l;t^.n^.r:=l;
t^.m^.l:=l+1;t^.m^.r:=t^.r;
maketree(t^.n);maketree(t^.m);
end;
end;
procedure jia(var t:point;i,k:longint);
var
m:longint;
begin
if t^.l<t^.r then begin
m:=(t^.l+t^.r) div 2;
if m<i then jia(t^.m,i,k)
else jia(t^.n,i,k);
end else
t^.c:=k;
end;
procedure bc(var t:point);
begin
if t^.l+1<t^.r then begin
bc(t^.n);bc(t^.m);
end;
if t^.l<t^.r then
if t^.n^.c<t^.m^.c then t^.c:=t^.m^.c
else t^.c:=t^.n^.c;
end;
procedure print(t:point;l,r:longint);
var
m:longint;
begin
if (t^.l>=l) and (t^.r<=r) then
if t^.c>a then a:=t^.c
else
else begin
m:=(t^.l+t^.r) div 2;
if (r<=m) then print(t^.n,l,r);
if (l>m) then print(t^.m,l,r);
if (l<=m) and (r>m) then begin
print(t^.n,l,m);
print(t^.m,m+1,r);
end;
end;
end;
procedure gai(var t:point;l,k:longint);
var
m:longint;
begin
m:=(t^.l+t^.r) div 2;
if t^.l<t^.r then begin
if l<=m then gai(t^.n,l,k);
if l>m then gai(t^.m,l,k);
if t^.n^.c<t^.m^.c then t^.c:=t^.m^.c
else t^.c:=t^.n^.c;
end else t^.c:=k;
end;
begin
readln(x,y);
new(t);
t^.l:=1;t^.r:=x;
maketree(t);
for i:=1 to x do begin
read(k);
jia(t,i,k);
end;
readln;
bc(t);
for i:=1 to y do begin
readln(j,k,l);
if j=1 then begin
print(t,k,l);
inc(r);
b[r]:=a;
a:=-1*maxlongint+1;
end;
if j=2 then gai(t,k,l);
end;
for i:=1 to r do
write(b[i],' ');
end.
- 1