-
Notifications
You must be signed in to change notification settings - Fork 0
/
10165_sweeping.cpp
53 lines (52 loc) · 1.16 KB
/
10165_sweeping.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
// 210826 #10165 ¹ö½º ³ë¼± Platinum V
// sweeping O(MlgM)
// circular -> making two linear is well-known
#include <iostream>
#include <algorithm>
#include <vector>
#define all(v) (v).begin(), (v).end()
#define press(v) (v).erase(unique(all(v)), (v).end())
using namespace std;
typedef pair<int, int> pi;
const int MAX = 500011;
int N, M;
vector<pair<pi, int>> v;
bool visit[MAX];
bool cmp(pair<pi, int> p1, pair<pi, int> p2) {
if (p1.first.first == p2.first.first)
return p1.first.second > p2.first.second;
return p1.first.first < p2.first.first;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> N >> M;
for (int i = 0; i < M; i++) {
int a, b;
cin >> a >> b;
if (a < b) {
v.push_back({ {a,b}, i });
v.push_back({{ a + N, b + N }, i});
}
else
v.push_back({ { a, b + N }, i });
}
sort(all(v), cmp);
int s = 0, e = 0, left = 0, right = 0;
for (int i = 0; i < v.size(); i++) {
s = v[i].first.first;
e = v[i].first.second;
int idx = v[i].second;
if (visit[idx])
continue;
if (left <= s && e <= right) {
visit[idx] = true;
continue;
}
left = s;
right = e;
}
for (int i = 0; i < M; i++) {
if (!visit[i])
cout << i + 1 << " ";
}
}