forked from mohitsh/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathposters.cpp
48 lines (48 loc) · 807 Bytes
/
posters.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// 2010-11-15
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while (t--)
{
int n,i;
int area[40000];
pair<int,int> a[80000];
scanf("%d",&n);
for (i=0; i<n; i++)
{
area[i]=0;
int b,e;
scanf("%d %d",&b,&e);
a[2*i]=make_pair(b,i);
a[2*i+1]=make_pair(e+1,1e6+i);
}
sort(a,a+2*n);
set<int> active;
for (i=0; i<2*n; i++)
{
if (!active.empty())
{
set<int>::iterator It=active.end();
--It;
area[*It]+=a[i].first-a[i-1].first;
}
if (a[i].second<1e6) //start
active.insert(a[i].second);
else
active.erase(a[i].second-1e6);
}
int cnt=0;
for (i=0; i<n; i++)
if (area[i]) cnt++;
printf("%d\n",cnt);
}
return 0;
}