This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define oo 1000000000
#define pb push_back
struct range{
int l, r;
int val;
bool operator<(range r1) const{
return val < r1.val;
}
};
int main() {
int n, q; cin >> n >> q;
vector<range> v(q);
for (int i = 0; i < q; ++i) {
cin >> v[i].l >> v[i].r >> v[i].val;
}
sort(v.rbegin(), v.rend());
vector<int> ans(n, -1);
vector<int> mn(n, -1);
vector<vector<int>> possible(n);
int k = 0;
bool flag = true;
for (int i = n-1; i >= 0; --i) {
int l = 0, r = n-1;
int x = n-1, y = 0;
while (k < q && v[k].val == i){
l = max(v[k].l, l); x = min(x, v[k].l);
r = min(v[k].r, r); y = max(y, v[k].r);
k++;
}
for (int j = x; j <= y; ++j) {
if (mn[j] == -1) mn[j] = i;
}
for (int j = l; j <= r; ++j){
if (mn[j] == i || mn[j] == -1) possible[i].pb(j);
}
if (possible[i].empty()) flag = false;
}
for (int i = 0; i < n && flag; ++i) {
int pos = -1;
for (int j = 0; j < possible[i].size(); ++j) {
if (ans[possible[i][j]] == -1) pos = possible[i][j];
}
ans[pos] = i;
}
for (auto x : ans) cout << x << " ";
return 0;
}
Compilation message (stderr)
rmq.cpp: In function 'int main()':
rmq.cpp:57:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for (int j = 0; j < possible[i].size(); ++j) {
| ~~^~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |