-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2568.cpp
76 lines (69 loc) · 1.51 KB
/
2568.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include<iostream>
#include<vector>
#define INF -987654321
using namespace std;
int n, maxIdx;
int l[500001];
int p[500001];
int answer[500001];
vector<int>tree;
vector<int>treeIdx;
int find(int num){
int s = 1, e = tree.size();
int mid;
while(s < e){
mid = (s + e)/2;
if(tree[mid] >= num){
e = mid;
}
else s = mid + 1;
}
return s;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 0; i < 500001; i++){
l[i] = -1;
}
for(int i = 1; i <= n; i++){
int tmp1, tmp2;
cin >> tmp1 >> tmp2;
l[tmp1] = tmp2;
maxIdx = max(maxIdx, tmp1);
}
tree.push_back(INF);
treeIdx.push_back(0);
for(int i = 1; i < 500001; i++){
if(l[i] == -1)continue;
if(l[i] > tree.back()){
tree.push_back(l[i]);
p[i] = treeIdx.back();
treeIdx.push_back(i);
}
else {
int idx = find(l[i]);
tree[idx] = l[i];
p[i] = treeIdx[idx-1];
treeIdx[idx] = i;
}
}
cout << n - (tree.size()-1) << '\n';
vector<int>survive;
int now = treeIdx.back();
while(now != 0){
survive.push_back(now);
now = p[now];
}
for(int i = 0; i < survive.size(); i++){
answer[survive[i]] = 1;
}
for(int i = 1; i <= maxIdx; i++){
if(l[i] == -1)continue;
if(answer[i] == 0){
cout << i << '\n';
}
}
}