# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
905162 |
2024-01-12T16:48:03 Z |
LOLOLO |
RMQ (NOI17_rmq) |
C++17 |
|
6 ms |
9052 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();
return 0;
}
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();
return 0;
}
}
for (int i = 0; i < n; i++)
cout << ans[i] << " ";
cout << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4604 KB |
Output is correct |
8 |
Correct |
2 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4444 KB |
Output is correct |
10 |
Correct |
2 ms |
4444 KB |
Output is correct |
11 |
Correct |
2 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4604 KB |
Output is correct |
8 |
Correct |
2 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4444 KB |
Output is correct |
10 |
Correct |
2 ms |
4444 KB |
Output is correct |
11 |
Correct |
2 ms |
4444 KB |
Output is correct |
12 |
Runtime error |
6 ms |
9052 KB |
Execution killed with signal 11 |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4604 KB |
Output is correct |
8 |
Correct |
2 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4444 KB |
Output is correct |
10 |
Correct |
2 ms |
4444 KB |
Output is correct |
11 |
Correct |
2 ms |
4444 KB |
Output is correct |
12 |
Runtime error |
6 ms |
9052 KB |
Execution killed with signal 11 |
13 |
Halted |
0 ms |
0 KB |
- |