http://poj.org/problem?id=2528
题目大意:有一面被划分成n格的墙,依次停入m两车,每辆车占据第l[i]~r[i]格的墙。问最后能看到几辆车。有多组数据。
线段树+离散。每次停车用不同的值覆盖一段给定区间,最后统计整段上不同的值有多少即为所求。
一开始抱着侥幸心理直接上线段树,结果MLE。。。
接下来又WA了两次。
第一次是没考虑下面这种情况:
1
3
1 10
1 3
5
答案应该是3,但是在离散的时候要是没有在3和5之间多插入一个点,就会处理成第2,3辆车把第一辆覆盖掉了。
第二次是数组开小了。因为离散的时候有多加入一些点,肯定要占用额外的空间,不过我已经开到8n的大小了还超。。。最后蛮试着开了16W居然给过了。。
AC CODE
program pku_2528;
var a:array[1..160000] of longint;
//============================================================================
procedure ins(be,en,now:longint);
var mid:longint;
begin
end;
//============================================================================
procedure ask(now:longint);
begin
end;
//============================================================================
procedure qsort(s,t:longint);
var k,i,j,tt:longint;
begin
end;
//============================================================================
procedure lisan;
var i:longint;
begin
end;
//============================================================================
procedure main;
var i:longint;
begin
end;
//============================================================================
begin
end.