-
Notifications
You must be signed in to change notification settings - Fork 0
/
ONEKING.cpp
62 lines (45 loc) · 931 Bytes
/
ONEKING.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
pii reverse(pii a) {
pii b;
b.second = a.first;
b.first = a.second;
return b;
}
int main()
{
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
pii strt_end[n];
pii end_strt[n];
map<pii, bool> hash;
for (int i = 0; i < n; ++i) {
cin >> strt_end[i].first;
cin >> strt_end[i].second;
end_strt[i].first = strt_end[i].second;
end_strt[i].second = strt_end[i].first;
hash[end_strt[i]] = false;
}
sort(end_strt, end_strt + n);
sort(strt_end, strt_end + n);
int bomb_ctr = 0;
int ite2 = 0;
for (int i = 0; i < n; i++ ) {
int end = end_strt[i].first;
if ( !hash[end_strt[i]] ) {
hash[end_strt[i]] = true;
while (ite2 < n && strt_end[ite2].first <= end ) {
hash[reverse(strt_end[ite2])] = true;
ite2++;
}
bomb_ctr++;
}
}
cout << bomb_ctr << endl;
}
return 0;
}