# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
905168 |
2024-01-12T17:00:24 Z |
LOLOLO |
RMQ (NOI17_rmq) |
C++14 |
|
0 ms |
0 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second
#define pb push_back
#define ep emplace
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define mem(f,x) memset(f , x , sizeof(f))
#define sz(x) (int)(x).size()
#define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define mxx *max_element
#define mnn *min_element
#define cntbit(x) __builtin_popcountll(x)
#define len(x) (int)(x.length())
const int N = 1e5 + 100;
vector <pair <int, int> > save[N];
int ans[N], seg[N * 4];
void upd(int id, int l, int r, int u, int v, int s) {
if (l > v || r < u)
return;
if (l >= u && r <= v) {
seg[id] = max(seg[id], s);
return;
}
int m = (l + r) / 2;
upd(id * 2, l, m, u, v, s);
upd(id * 2 + 1, m + 1, r, u, v, s);
}
int get(int id, int l, int r, int p) {
if (l > p || r < p)
return 0;
int ans = seg[id];
if (l == r)
return ans;
int m = (l + r) / 2;
return max({ans, get(id * 2, l, m, p), get(id * 2 + 1, m + 1, r, p)});
}
int n, q;
bool cmp(int a, int b) {
return get(1, 0, n - 1, a) < get(1, 0, n - 1, b);
}
void out() {
for (int i = 0; i < n; i++)
cout << -1 << " ";
exit(0);
}
int main() {
mem(ans, -1);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> q;
for (int i = 1; i <= q; i++) {
int l, r, v;
cin >> l >> r >> v;
upd(1, 0, n - 1, l, r, v);
save[v].pb(make_pair(l, r));
}
set <int> on;
for (int i = 0; i < n; i++) {
on.insert(i);
}
vector <int> need, val;
for (int i = n - 1; i >= 0; i--) {
if (save[i].empty()) {
val.pb(i);
continue;
}
int l = 0, r = n - 1;
for (auto x : save[i]) {
l = max(l, x.f);
r = min(r, x.s);
}
auto it = on.lower_bound(l);
if (it != on.end() && *it <= r) {
ans[*it] = i;
on.erase(*it);
} else {
out();
}
for (auto x : save[i]) {
int l = x.f, r = x.s;
auto it = on.lower_bound(l);
vector <int> add;
while (it != on.end() && *it <= r) {
add.pb(: *it);
it = next(it);
}
for (auto e : add) {
on.erase(e);
need.pb(e);
}
}
}
sort(all(need), cmp);
sort(all(val));
for (int i = 0; i < sz(val); i++) {
ans[need[i]] = val[i];
}
for (int i = 0; i < n; i++) {
if (ans[i] < get(1, 0, n - 1, i)) {
out();
}
}
for (int i = 0; i < n; i++)
cout << ans[i] << " ";
cout << '\n';
return 0;
}
Compilation message
rmq.cpp: In function 'int main()':
rmq.cpp:112:24: error: expected primary-expression before ':' token
112 | add.pb(: *it);
| ^