Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int dd = (int)4e5 + 1;
- const int inf = (1ll << 31) - 1;
- vector<pair<int, int> > Q;
- vector<int> iP;
- void up(int i) {
- if (i == 1) return;
- if (Q[i / 2] < Q[i]) {
- swap(Q[i], Q[i / 2]);
- swap(iP[Q[i].second], iP[Q[i / 2].second]);
- up(i / 2);
- }
- }
- void down(int i) {
- int f = 0;
- if (i * 2 < (int)Q.size() && Q[i] < Q[i * 2]) {
- swap(Q[i], Q[i * 2]);
- swap(iP[Q[i].second], iP[Q[i * 2].second]);
- f = 1;
- }
- if (i * 2 + 1 < (int)Q.size() && Q[i] < Q[i * 2 + 1]) {
- if (f) {
- swap(Q[i], Q[i * 2]);
- swap(iP[Q[i].second], iP[Q[i * 2].second]);
- }
- swap(Q[i], Q[i * 2 + 1]);
- swap(iP[Q[i].second], iP[Q[i * 2 + 1].second]);
- f = 2;
- }
- if (f) down(i * 2 + f - 1);
- }
- int get() {
- return Q[1].first;
- }
- void eget() {
- swap(Q[1], Q.back());
- swap(iP[Q[1].second], iP[Q.back().second]);
- iP[Q.back().second] = -1;
- Q.pop_back();
- if ((int)Q.size() > 1) down(1);
- }
- void dk(int a, int b) {
- Q[a].first = b;
- up(a);
- }
- void del(int a) {
- dk(a, inf);
- eget();
- }
- void push(int x) {
- Q.push_back({ x, (int)iP.size() });
- iP.push_back((int)Q.size() - 1);
- up((int)Q.size() - 1);
- }
- vector<pair<int, int> > add[dd];
- vector<int> ded[dd];
- int main() {
- int n, m;
- scanf("%d %d", &n, &m);
- Q.push_back({ -1, 0 });
- for (int i = 0; i < m; ++i) {
- int l, r, x;
- scanf("%d %d %d", &l, &r, &x);
- --l, --r;
- add[l].push_back({ x, r });
- }
- int cnt = 0;
- for (int i = 0; i < n; ++i) {
- for (auto j : add[i]) {
- push(j.first);
- ded[j.second + 1].push_back(cnt++);
- }
- for (int j : ded[i])
- del(iP[j]);
- if ((int)Q.size() == 1) printf("1 ");
- else printf("%d ", get());
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement