Submission #391301

# Submission time Handle Problem Language Result Execution time Memory
391301 2021-04-18T13:11:13 Z BThero RMQ (NOI17_rmq) C++17
100 / 100
103 ms 11912 KB
// 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
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 2 ms 2636 KB Output is correct
11 Correct 2 ms 2640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 2 ms 2636 KB Output is correct
11 Correct 2 ms 2640 KB Output is correct
12 Correct 2 ms 2764 KB Output is correct
13 Correct 4 ms 2764 KB Output is correct
14 Correct 2 ms 2636 KB Output is correct
15 Correct 2 ms 2764 KB Output is correct
16 Correct 3 ms 2764 KB Output is correct
17 Correct 3 ms 2764 KB Output is correct
18 Correct 2 ms 2764 KB Output is correct
19 Correct 2 ms 2764 KB Output is correct
20 Correct 2 ms 2640 KB Output is correct
21 Correct 2 ms 2636 KB Output is correct
22 Correct 2 ms 2636 KB Output is correct
23 Correct 2 ms 2636 KB Output is correct
24 Correct 2 ms 2636 KB Output is correct
25 Correct 2 ms 2636 KB Output is correct
26 Correct 2 ms 2636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 2 ms 2636 KB Output is correct
11 Correct 2 ms 2640 KB Output is correct
12 Correct 2 ms 2764 KB Output is correct
13 Correct 4 ms 2764 KB Output is correct
14 Correct 2 ms 2636 KB Output is correct
15 Correct 2 ms 2764 KB Output is correct
16 Correct 3 ms 2764 KB Output is correct
17 Correct 3 ms 2764 KB Output is correct
18 Correct 2 ms 2764 KB Output is correct
19 Correct 2 ms 2764 KB Output is correct
20 Correct 2 ms 2640 KB Output is correct
21 Correct 2 ms 2636 KB Output is correct
22 Correct 2 ms 2636 KB Output is correct
23 Correct 2 ms 2636 KB Output is correct
24 Correct 2 ms 2636 KB Output is correct
25 Correct 2 ms 2636 KB Output is correct
26 Correct 2 ms 2636 KB Output is correct
27 Correct 79 ms 10072 KB Output is correct
28 Correct 74 ms 11332 KB Output is correct
29 Correct 65 ms 10752 KB Output is correct
30 Correct 103 ms 11912 KB Output is correct
31 Correct 65 ms 9616 KB Output is correct
32 Correct 79 ms 9744 KB Output is correct
33 Correct 31 ms 8660 KB Output is correct
34 Correct 20 ms 7164 KB Output is correct
35 Correct 37 ms 10680 KB Output is correct
36 Correct 44 ms 7420 KB Output is correct
37 Correct 63 ms 7980 KB Output is correct
38 Correct 9 ms 4428 KB Output is correct
39 Correct 55 ms 7524 KB Output is correct
40 Correct 2 ms 2636 KB Output is correct
41 Correct 2 ms 2636 KB Output is correct