- 野生动物园
- 2012-11-19 11:07:33 @
├ 测试数据 01:运行时错误... (31ms, 26440KB)
堆栈溢出
├ 测试数据 02:运行时错误... (31ms, 26440KB)
堆栈溢出
├ 测试数据 03:运行时错误... (31ms, 26440KB)
堆栈溢出
├ 测试数据 04:运行时错误... (46ms, 26440KB)
堆栈溢出
├ 测试数据 05:运行时错误... (31ms, 26440KB)
堆栈溢出
├ 测试数据 06:运行时错误... (46ms, 26440KB)
堆栈溢出
├ 测试数据 07:答案错误... (171ms, 6876KB)
├ 测试数据 08:答案错误... (241ms, 6876KB)
├ 测试数据 09:运行时错误... (93ms, 26440KB)
堆栈溢出
├ 测试数据 10:运行时错误... (93ms, 26440KB)
堆栈溢出
type
cc=record
l,k,r:Longint;
end;
type
c=record
l,r,ran,v,tot:Longint;
end;
var
tr:array[0..140011]of c;
t:array[0..150001]of longint;
q:array[0..150001]of cc;
a,ans:array[0..140001]of longint;
i,j,k,m,n,nl,nr,root,tree:Longint;
procedure qsort(l,r:Longint);
var
i,j,m1,m2,p1:Longint;
p:cc;
begin
i:=l;
j:=r;
m1:=q[(l+r)shr 1].l;
m2:=q[(l+r)shr 1].r;
repeat
while (q[i].lm2))do dec(j);
if ij;
if il then qsort(l,j);
end;
procedure init;
begin
readln(n,m);
for i:=1 to n do
read(a[i]);
for i:=1 to m do
with q[i] do
read(l,r,k);
for i:=1 to m do
t[i]:=i;
qsort(1,m);
end;
procedure l_rorate(var x:Longint);
var
y:Longint;
begin
y:=tr[x].l;tr[x].l:=tr[y].r;tr[y].r:=x;
tr[y].tot:=tr[x].tot;
tr[x].tot:=tr[tr[x].l].tot+tr[tr[x].r].tot+1;
x:=y;
end;
procedure r_rorate(var x:Longint);
var
y:Longint;
begin
y:=tr[x].r;tr[x].r:=tr[y].l;tr[y].l:=x;
tr[y].tot:=tr[x].tot;
tr[x].tot:=tr[tr[x].l].tot+tr[tr[x].r].tot+1;
x:=y;
end;
procedure ins(var k:Longint;v:Longint);
begin
if k=0 then
begin
inc(tree);
k:=tree;
tr[k].tot:=1;
tr[k].v:=v;
tr[k].ran:=random(10000000)+1;
exit;
end;
inc(tr[k].tot);
if v=rank then exit(find(l,rank))
else
if tr[l].tot+1=rank then exit(tr[k].v)
else exit(find(r,rank-tr[l].tot-1));
end;
begin
assign(input,'d:\1.txt');reset(input);
fillchar(tr,sizeof(tr),0);
fillchar(a,sizeof(a),0);
fillchar(q,sizeof(q),0);
fillchar(t,sizeof(t),0);
fillchar(ans,sizeof(ans),0);
init;
nl:=1;
nr:=0;
root:=0;
tree:=0;
for i:=1 to m do
begin
for j:=nl to q[i].l-1 do
delete(root,a[j]);
nl:=q[i].l;
for j:=nr+1 to q[i].r do
ins(root,a[j]);
nr:=q[i].r;
ans[i]:=find(root,q[i].k);
end;
for i:=1 to m do
begin
write(ans[t[i]]);
if i mod 1000=0 then writeln;
end;
close(input);
end.
1 条评论
-
琉璃盏 LV 10 @ 2015-01-16 21:22:25
。。。
- 1