-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10165.cpp
More file actions
55 lines (44 loc) · 1.21 KB
/
10165.cpp
File metadata and controls
55 lines (44 loc) · 1.21 KB
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
#include <bits/stdc++.h>
#define SETTING ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
using namespace std ;
int N, M, s, e ;
struct node {
int start, end, station ;
node(int x, int y, int z) : start(x), end(y), station(z) {}
};
bool compare(node a, node b) {
if(a.start == b.start) return a.end > b.end ;
return a.start < b.start ;
}
bool comp_station(node a, node b) {
return a.station < b.station ;
}
vector<node> arr ;
int main()
{
SETTING ;
cin >> N >> M ;
for(int i = 0 ; i < M ; i++)
{
cin>> s >> e ;
if(s > e) {
arr.push_back(node(s, e + N, i + 1)) ;
arr.push_back(node(s - N, e, i + 1)) ;
}
else arr.push_back(node(s, e, i + 1)) ;
}
sort(arr.begin(), arr.end(), compare) ;
vector<node> sort_start ;
for(int i = 0 ; i < arr.size() ; i++)
{
if(sort_start.empty() || sort_start.back().end < arr[i].end) sort_start.push_back(arr[i]) ;
}
sort(sort_start.begin(), sort_start.end(), comp_station) ;
int prev = INT_MAX ;
for(auto i : sort_start)
if(i.station != prev)
{
cout << i.station << " " ; prev = i.station ;
}
}