Submission #917514

# Submission time Handle Problem Language Result Execution time Memory
917514 2024-01-28T11:17:08 Z 406 RMQ (NOI17_rmq) C++17
100 / 100
70 ms 19148 KB
#include <bits/stdc++.h>
#define int int64_t
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)

using namespace std;
using ar = array<int, 2>;

const int64_t INF = 1ll << 60;
const int N = 1e5 + 5;

vector<ar> delta[N];
int n, q, re[N], mx[N], L[N], R[N];
vector<int> M[N];

void imp() {
        FOR(i, 0, n) cout << "-1 ";
        exit(0);
}

signed main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr); 
        cin >> n >> q;
        fill(L, L + n, -1);
        fill(R, R + n, n);
        while (q--) {
                int l, r, x;
                cin >> l >> r >> x;
                L[x] = max(L[x], l);
                R[x] = min(R[x], r);
                delta[l].push_back({x, +1});
                delta[r + 1].push_back({x, -1});
        }
        multiset<int> S;
        vector<int> cur;
        FOR(i, 0, n) {
                for (auto [x, d]: delta[i]) {
                        if (d == 1) S.insert(x);
                        else S.erase(S.find(x));
                }
                if (S.size()) mx[i] = *S.rbegin(), M[mx[i]].push_back(i);
                else cur.push_back(i);
        }

        FOR(i, 0, n) {
               int l = L[i], r = R[i];
               if (l == -1) {
                       if (cur.empty()) imp();
                       re[cur.back()] = i;
                       cur.pop_back();
                       continue;
               }
               if (l > r || M[i].empty()) imp();
               int x = -1;
               while (M[i].size()) {
                       x = M[i].back(); M[i].pop_back();
                       if (l <= x && x <= r) break;
                       cur.push_back(x);
               }
               if (!(l <= x && x <= r)) imp();
               re[x] = i;
               for (auto t: M[i]) cur.push_back(t);
        }
        FOR(i, 0, n)
                cout << re[i] << ' ';
        return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8280 KB Output is correct
2 Correct 2 ms 8284 KB Output is correct
3 Correct 3 ms 8284 KB Output is correct
4 Correct 3 ms 8284 KB Output is correct
5 Correct 2 ms 8284 KB Output is correct
6 Correct 2 ms 8280 KB Output is correct
7 Correct 3 ms 8284 KB Output is correct
8 Correct 2 ms 8284 KB Output is correct
9 Correct 3 ms 8028 KB Output is correct
10 Correct 2 ms 8280 KB Output is correct
11 Correct 2 ms 8284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8280 KB Output is correct
2 Correct 2 ms 8284 KB Output is correct
3 Correct 3 ms 8284 KB Output is correct
4 Correct 3 ms 8284 KB Output is correct
5 Correct 2 ms 8284 KB Output is correct
6 Correct 2 ms 8280 KB Output is correct
7 Correct 3 ms 8284 KB Output is correct
8 Correct 2 ms 8284 KB Output is correct
9 Correct 3 ms 8028 KB Output is correct
10 Correct 2 ms 8280 KB Output is correct
11 Correct 2 ms 8284 KB Output is correct
12 Correct 2 ms 8536 KB Output is correct
13 Correct 3 ms 8284 KB Output is correct
14 Correct 2 ms 8280 KB Output is correct
15 Correct 3 ms 8284 KB Output is correct
16 Correct 3 ms 8284 KB Output is correct
17 Correct 3 ms 8280 KB Output is correct
18 Correct 2 ms 8280 KB Output is correct
19 Correct 3 ms 8284 KB Output is correct
20 Correct 2 ms 8536 KB Output is correct
21 Correct 3 ms 8284 KB Output is correct
22 Correct 2 ms 8284 KB Output is correct
23 Correct 3 ms 8284 KB Output is correct
24 Correct 4 ms 8280 KB Output is correct
25 Correct 3 ms 8280 KB Output is correct
26 Correct 2 ms 8028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8280 KB Output is correct
2 Correct 2 ms 8284 KB Output is correct
3 Correct 3 ms 8284 KB Output is correct
4 Correct 3 ms 8284 KB Output is correct
5 Correct 2 ms 8284 KB Output is correct
6 Correct 2 ms 8280 KB Output is correct
7 Correct 3 ms 8284 KB Output is correct
8 Correct 2 ms 8284 KB Output is correct
9 Correct 3 ms 8028 KB Output is correct
10 Correct 2 ms 8280 KB Output is correct
11 Correct 2 ms 8284 KB Output is correct
12 Correct 2 ms 8536 KB Output is correct
13 Correct 3 ms 8284 KB Output is correct
14 Correct 2 ms 8280 KB Output is correct
15 Correct 3 ms 8284 KB Output is correct
16 Correct 3 ms 8284 KB Output is correct
17 Correct 3 ms 8280 KB Output is correct
18 Correct 2 ms 8280 KB Output is correct
19 Correct 3 ms 8284 KB Output is correct
20 Correct 2 ms 8536 KB Output is correct
21 Correct 3 ms 8284 KB Output is correct
22 Correct 2 ms 8284 KB Output is correct
23 Correct 3 ms 8284 KB Output is correct
24 Correct 4 ms 8280 KB Output is correct
25 Correct 3 ms 8280 KB Output is correct
26 Correct 2 ms 8028 KB Output is correct
27 Correct 70 ms 18636 KB Output is correct
28 Correct 52 ms 17396 KB Output is correct
29 Correct 41 ms 15896 KB Output is correct
30 Correct 62 ms 18216 KB Output is correct
31 Correct 45 ms 16464 KB Output is correct
32 Correct 53 ms 19148 KB Output is correct
33 Correct 9 ms 10448 KB Output is correct
34 Correct 7 ms 9720 KB Output is correct
35 Correct 13 ms 11212 KB Output is correct
36 Correct 43 ms 14152 KB Output is correct
37 Correct 61 ms 16340 KB Output is correct
38 Correct 5 ms 9112 KB Output is correct
39 Correct 68 ms 15696 KB Output is correct
40 Correct 3 ms 8284 KB Output is correct
41 Correct 2 ms 8284 KB Output is correct