-
Notifications
You must be signed in to change notification settings - Fork 87
/
029-02.cpp
33 lines (33 loc) · 995 Bytes
/
029-02.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
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int W, N;
cin >> W >> N;
vector<int> L(N), R(N);
for (int i = 0; i < N; ++i) {
cin >> L[i] >> R[i];
--L[i];
}
vector<int> compression;
for (int i = 0; i < N; ++i) {
compression.push_back(L[i]);
compression.push_back(R[i]);
}
sort(compression.begin(), compression.end());
compression.erase(unique(compression.begin(), compression.end()), compression.end());
for (int i = 0; i < N; ++i) {
L[i] = lower_bound(compression.begin(), compression.end(), L[i]) - compression.begin();
R[i] = lower_bound(compression.begin(), compression.end(), R[i]) - compression.begin();
}
vector<int> h(compression.size() - 1);
for (int i = 0; i < N; ++i) {
int height = *max_element(h.begin() + L[i], h.begin() + R[i]) + 1;
fill(h.begin() + L[i], h.begin() + R[i], height);
cout << height << '\n';
}
return 0;
}