记录编号 |
50645 |
评测结果 |
AAAAAAAAAA |
题目名称 |
贪婪大陆 |
最终得分 |
100 |
用户昵称 |
DavidMason |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.439 s |
提交时间 |
2012-11-27 22:29:20 |
内存使用 |
3.22 MiB |
显示代码纯文本
type rr=record
left,right:longint;
end;
var
tree:array[0..400000] of rr;
n,m,tot,total,left,right:longint;
procedure init;
begin
assign(input,'greedisland.in'); reset(input);
assign(output,'greedisland.out'); rewrite(output);
read(n,m);
end;
procedure terminate;
begin
close(input); close(output); halt;
end;
procedure insert1(t,i,l,r:longint);
var
mid:longint;
begin
if (r<i) or (l>i) then exit;
if l=r then begin
inc(tree[t].left);
exit;
end;
mid:=(l+r) div 2;
insert1(t*2,i,l,mid);
insert1(t*2+1,i,mid+1,r);
tree[t].left:=tree[t*2].left+tree[t*2+1].left;
end;
procedure insert2(t,i,l,r:longint);
var
mid:longint;
begin
if (r<i) or (l>i) then exit;
if l=r then begin
inc(tree[t].right);
exit;
end;
mid:=(l+r) div 2;
insert2(t*2,i,l,mid);
insert2(t*2+1,i,mid+1,r);
tree[t].right:=tree[t*2].right+tree[t*2+1].right;
end;
procedure get1(t,l,r:longint);
var
mid:longint;
begin
if (l>left) or (r<1) then exit;
if (l>=1) and (r<=left) then begin
inc(tot,tree[t].right);
exit;
end;
mid:=(l+r) div 2;
get1(t*2,l,mid);
get1(t*2+1,mid+1,r);
end;
procedure get2(t,l,r:longint);
var
mid:longint;
begin
if (l>n) or (r<right) then exit;
if (l>=right) and (r<=n) then begin
inc(tot,tree[t].left);
exit;
end;
mid:=(l+r) div 2;
get2(t*2,l,mid);
get2(t*2+1,mid+1,r);
end;
procedure main;
var
i,x,l,r:longint;
begin
total:=0;
for i:=1 to m do begin
read(x,l,r);
if x=1 then begin
insert1(1,l,1,n);
insert2(1,r,1,n);
inc(total);
end else begin
tot:=0;
if l>1 then left:=l-1 else left:=0;
get1(1,1,n);
if r<n then right:=r+1 else right:=n;
get2(1,1,n);
writeln(total-tot);
end;
end;
end;
begin
init;
main;
terminate;
end.