This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// chrono::system_clock::now().time_since_epoch().count()
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define debug(x) cerr << #x << " = " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MAXN = (int)1e5 + 5;
vi mem[MAXN];
int t[MAXN << 2];
int lim[MAXN], ans[MAXN];
array<int, 3> que[MAXN];
pii seg[MAXN];
int n, q;
void update(int v, int tl, int tr, int l, int r, int x) {
if (l > r || tl > r || tr < l) {
return;
}
if (l <= tl && tr <= r) {
t[v] = max(t[v], x);
return;
}
int mid = (tl + tr) >> 1;
int c1 = (v << 1), c2 = (c1 | 1);
update(c1, tl, mid, l, r, x);
update(c2, mid + 1, tr, l, r, x);
}
void go(int v, int tl, int tr, int x = 0) {
x = max(x, t[v]);
if (tl == tr) {
lim[tl] = x;
return;
}
int mid = (tl + tr) >> 1;
int c1 = (v << 1), c2 = (c1 | 1);
go(c1, tl, mid, x);
go(c2, mid + 1, tr, x);
}
void solve() {
cin >> n >> q;
fill(seg, seg + n, mp(0, n - 1));
rep (i, 0, q) {
int l, r, x;
cin >> l >> r >> x;
que[i] = {l, r, x};
seg[x].fi = max(seg[x].fi, l);
seg[x].se = min(seg[x].se, r);
update(1, 0, n - 1, l, r, x);
}
go(1, 0, n - 1);
rep (i, 0, n) {
mem[lim[i]].pb(i);
}
fill(ans, ans + n, -1);
set<int> S;
rep (i, 0, n) {
for (int x : mem[i]) {
S.insert(x);
}
auto it = S.lower_bound(seg[i].fi);
if (it == S.end() || *it > seg[i].se) {
rep (i, 0, n) {
cout << -1 << " \n"[i == n - 1];
}
return;
}
ans[*it] = i;
S.erase(it);
}
rep (i, 0, n) {
cout << ans[i] << " \n"[i == n - 1];
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tt = 1;
for (int i = 1; i <= tt; ++i) {
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |