# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
828819 |
2023-08-17T16:43:36 Z |
NK_ |
RMQ (NOI17_rmq) |
C++17 |
|
168 ms |
21972 KB |
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz(x) int(x.size())
template<class T> using V = vector<T>;
using vi = V<int>;
using ll = long long;
using pi = pair<int, int>;
using vpi = V<pi>;
using vl = V<ll>;
using db = double;
const int INF = 1e9 + 10;
struct ST {
int level(int x) { return 31 - __builtin_clz(x); }
vi v; V<vi> jmp; int comb(int a, int b) { return min(a, b); }
void init(const vi& _v) {
v = _v; jmp = {v};
for(int j = 1; (1<<j) <= sz(v); j++) {
jmp.pb(vi(sz(v) - (1<<j) + 1));
for(int i = 0; i < sz(jmp[j]); i++) jmp[j][i] = comb(jmp[j-1][i], jmp[j-1][i+(1<<(j-1))]);
}
}
int query(int l, int r) {
int d = level(r-l+1);
return comb(jmp[d][l], jmp[d][r-(1<<d)+1]);
}
};
int main() {
cin.tie(0)->sync_with_stdio(0);
int N, Q; cin >> N >> Q;
V<vi> E(N+1); V<array<int, 3>> q;
vi amt(N);
for(int i = 0; i < Q; i++) {
int l, r, x; cin >> l >> r >> x;
amt[x]++; q.pb({l, r, x});
E[l].pb(x);
E[r+1].pb(~x);
}
auto impossible = [&]() {
for(int i = 0; i < N; i++) cout << -1 << " ";
cout << nl;
exit(0-0);
};
set<int> have;
for(int i = 0; i < N; i++) have.insert(i);
multiset<int> S = {-1}, G = {-1}; vi A(N), mn(N);
map<int, int> C;
for(int x = 0; x < N; x++) {
for(auto& v : E[x]) {
if (v < 0) {
v = ~v;
if (C[v] == amt[v]) G.erase(v);
C[v]--, S.erase(S.find(v));
} else {
C[v]++, S.insert(v);
if (C[v] == amt[v]) { G.insert(v); if (have.count(v)) have.erase(v); }
}
}
A[x] = *rbegin(G);
mn[x] = *rbegin(S);
}
// for(auto x : A) cout << x << " ";
// cout << nl;
vi CNT(N); for(auto x : A) if (x != -1) CNT[x]++;
vi ord(N); iota(begin(ord), end(ord), 0);
sort(begin(ord), end(ord), [&](int x, int y) { return mn[x] > mn[y]; });
for(auto i : ord) {
int x = A[i];
if (x != -1 && CNT[x] == 1) continue;
// cout << i << " " << *rbegin(have) << " " << mn[i] << endl;
auto it = have.lower_bound(mn[i]);
if (it == end(have)) continue;
A[i] = *it; have.erase(it);
if (x != -1) CNT[x]--;
}
ST st; st.init(A);
for(int j = 0; j < Q; j++) {
auto [l, r, x] = q[j];
// cout << st.query(l, r) << " " << x << endl;
if (st.query(l, r) != x) impossible();
}
for(auto x : A) cout << x << " ";
cout << nl;
exit(0-0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Partially correct |
0 ms |
212 KB |
Output is partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Partially correct |
0 ms |
212 KB |
Output is partially correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
436 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Partially correct |
0 ms |
212 KB |
Output is partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Partially correct |
0 ms |
212 KB |
Output is partially correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
436 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Partially correct |
0 ms |
212 KB |
Output is partially correct |
27 |
Correct |
70 ms |
15216 KB |
Output is correct |
28 |
Correct |
64 ms |
15488 KB |
Output is correct |
29 |
Correct |
56 ms |
14080 KB |
Output is correct |
30 |
Correct |
70 ms |
16624 KB |
Output is correct |
31 |
Correct |
53 ms |
12464 KB |
Output is correct |
32 |
Correct |
56 ms |
14124 KB |
Output is correct |
33 |
Correct |
24 ms |
9396 KB |
Output is correct |
34 |
Correct |
16 ms |
6484 KB |
Output is correct |
35 |
Correct |
32 ms |
11740 KB |
Output is correct |
36 |
Correct |
122 ms |
20740 KB |
Output is correct |
37 |
Correct |
168 ms |
21972 KB |
Output is correct |
38 |
Correct |
20 ms |
9220 KB |
Output is correct |
39 |
Correct |
61 ms |
15312 KB |
Output is correct |
40 |
Correct |
0 ms |
320 KB |
Output is correct |
41 |
Partially correct |
0 ms |
320 KB |
Output is partially correct |