Submission #1106948

# Submission time Handle Problem Language Result Execution time Memory
1106948 2024-10-31T09:43:47 Z elush None (JOI16_ho_t5) C++14
100 / 100
332 ms 35656 KB
#include <bits/stdc++.h>
#define chkmax(a, b) a = max(a, b)
#define all(v) v.begin(), v.end()
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef vector<vi> vvi;
typedef vector<pii> vii;

void operator+=(pii &p1, pii p2) {
    p1.x += p2.x, p1.y += p2.y;
}

struct Seg {
    int n;
    vii ri, le, lazy;
    Seg() {}
    Seg(int m) {
        for (n = 1; n < m; n <<= 1);
        ri.resize(2 * n), le.resize(2 * n);
        lazy.resize(2 * n);
    }
    void Push(int i) {
        ri[i << 1] += lazy[i];
        le[i << 1] += lazy[i];
        lazy[i << 1] += lazy[i];
        ri[i << 1 | 1] += lazy[i];
        le[i << 1 | 1] += lazy[i];
        lazy[i << 1 | 1] += lazy[i];
        lazy[i] = {0, 0};
    }
    void Pull(int i) {
        ri[i] = ri[i << 1 | 1];
        le[i] = le[i << 1];
    }
    void Update(int a, int b, pii add, int i, int l, int r) {
        if (a <= l && r <= b) {
            lazy[i] += add;
            le[i] += add;
            ri[i] += add;
            return;
        }
        if (r <= a || b <= l) return;
        Push(i);
        Update(a, b, add, i << 1, l, (l + r) >> 1);
        Update(a, b, add, i << 1 | 1, (l + r) >> 1, r);
        Pull(i);
    }
    void Update(int a, int b, ll x, ll y) {
        Update(a, b, {x, y}, 1, 0, n);
    }
    int QueryPrefix(ll dig) {
        int i = 1;
        while (i < n) {
            Push(i);
            i <<= 1;
            if (ri[i].x + ri[i].y <= dig) i |= 1;
        }
        if (ri[i].x + ri[i].y <= dig) i++;
        return i - n;
    }
    int QuerySuffix(ll dig) {
        int i = 1;
        while (i < n) {
            Push(i);
            i = i << 1 | 1;
            if (le[i].x - le[i].y >= dig) i ^= 1;
        }
        if (le[i].x - le[i].y >= dig) i--;
        return i - n;
    }
    ll Query(int i) {
        ll ans = 0;
        for (i += n; i; i >>= 1) ans += lazy[i].y;
        return ans;
    }
};

vi Solve(int n, int q, vector<int> x, vector<int> d, vector<int> l) {
    Seg seg(n + 1);
    for (int i = 0; i < seg.n; i++) {
        seg.Update(i, i + 1, i, 0);
    }
    reverse(all(x)), reverse(all(d)), reverse(all(l));
    for (int i = 0; i < q; i++) {
        if (d[i] == 1) {
            int r = seg.QueryPrefix(x[i]);
            seg.Update(0, r, -l[i], l[i]);
        } else {
            int le = seg.QuerySuffix(x[i] + 1);
            seg.Update(le + 1, seg.n, l[i], l[i]);
        }
    }
    vi ans(n);
    for (int i = 1; i <= n; i++) ans[i - 1] = seg.Query(i);
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int N, Q;
    cin >> N >> Q;
    std::vector<int> X(Q), D(Q), L(Q);
    for (int i = 0; i < Q; i++) cin >> X[i] >> D[i] >> L[i];
    vi ans = Solve(N, Q, X, D, L);
    for (int i = 0; i < N; i++) cout << ans[i] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 456 KB Output is correct
2 Correct 1 ms 472 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 456 KB Output is correct
2 Correct 1 ms 472 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 3 ms 848 KB Output is correct
29 Correct 3 ms 848 KB Output is correct
30 Correct 3 ms 848 KB Output is correct
31 Correct 3 ms 848 KB Output is correct
32 Correct 4 ms 860 KB Output is correct
33 Correct 3 ms 848 KB Output is correct
34 Correct 3 ms 848 KB Output is correct
35 Correct 3 ms 848 KB Output is correct
36 Correct 3 ms 848 KB Output is correct
37 Correct 4 ms 848 KB Output is correct
38 Correct 3 ms 848 KB Output is correct
39 Correct 3 ms 848 KB Output is correct
40 Correct 3 ms 984 KB Output is correct
41 Correct 3 ms 848 KB Output is correct
42 Correct 3 ms 848 KB Output is correct
43 Correct 4 ms 848 KB Output is correct
44 Correct 3 ms 848 KB Output is correct
45 Correct 3 ms 860 KB Output is correct
46 Correct 3 ms 848 KB Output is correct
47 Correct 3 ms 848 KB Output is correct
48 Correct 3 ms 848 KB Output is correct
49 Correct 3 ms 1020 KB Output is correct
50 Correct 3 ms 848 KB Output is correct
51 Correct 3 ms 784 KB Output is correct
52 Correct 3 ms 848 KB Output is correct
53 Correct 3 ms 848 KB Output is correct
54 Correct 3 ms 848 KB Output is correct
55 Correct 3 ms 780 KB Output is correct
56 Correct 3 ms 1016 KB Output is correct
57 Correct 3 ms 848 KB Output is correct
58 Correct 3 ms 860 KB Output is correct
59 Correct 3 ms 1020 KB Output is correct
60 Correct 3 ms 980 KB Output is correct
61 Correct 3 ms 848 KB Output is correct
62 Correct 3 ms 1016 KB Output is correct
63 Correct 3 ms 848 KB Output is correct
64 Correct 3 ms 1016 KB Output is correct
65 Correct 3 ms 848 KB Output is correct
66 Correct 3 ms 848 KB Output is correct
67 Correct 3 ms 780 KB Output is correct
68 Correct 3 ms 848 KB Output is correct
69 Correct 3 ms 848 KB Output is correct
70 Correct 2 ms 848 KB Output is correct
71 Correct 2 ms 848 KB Output is correct
72 Correct 2 ms 848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 456 KB Output is correct
2 Correct 1 ms 472 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 3 ms 848 KB Output is correct
29 Correct 3 ms 848 KB Output is correct
30 Correct 3 ms 848 KB Output is correct
31 Correct 3 ms 848 KB Output is correct
32 Correct 4 ms 860 KB Output is correct
33 Correct 3 ms 848 KB Output is correct
34 Correct 3 ms 848 KB Output is correct
35 Correct 3 ms 848 KB Output is correct
36 Correct 3 ms 848 KB Output is correct
37 Correct 4 ms 848 KB Output is correct
38 Correct 3 ms 848 KB Output is correct
39 Correct 3 ms 848 KB Output is correct
40 Correct 3 ms 984 KB Output is correct
41 Correct 3 ms 848 KB Output is correct
42 Correct 3 ms 848 KB Output is correct
43 Correct 4 ms 848 KB Output is correct
44 Correct 3 ms 848 KB Output is correct
45 Correct 3 ms 860 KB Output is correct
46 Correct 3 ms 848 KB Output is correct
47 Correct 3 ms 848 KB Output is correct
48 Correct 3 ms 848 KB Output is correct
49 Correct 3 ms 1020 KB Output is correct
50 Correct 3 ms 848 KB Output is correct
51 Correct 3 ms 784 KB Output is correct
52 Correct 3 ms 848 KB Output is correct
53 Correct 3 ms 848 KB Output is correct
54 Correct 3 ms 848 KB Output is correct
55 Correct 3 ms 780 KB Output is correct
56 Correct 3 ms 1016 KB Output is correct
57 Correct 3 ms 848 KB Output is correct
58 Correct 3 ms 860 KB Output is correct
59 Correct 3 ms 1020 KB Output is correct
60 Correct 3 ms 980 KB Output is correct
61 Correct 3 ms 848 KB Output is correct
62 Correct 3 ms 1016 KB Output is correct
63 Correct 3 ms 848 KB Output is correct
64 Correct 3 ms 1016 KB Output is correct
65 Correct 3 ms 848 KB Output is correct
66 Correct 3 ms 848 KB Output is correct
67 Correct 3 ms 780 KB Output is correct
68 Correct 3 ms 848 KB Output is correct
69 Correct 3 ms 848 KB Output is correct
70 Correct 2 ms 848 KB Output is correct
71 Correct 2 ms 848 KB Output is correct
72 Correct 2 ms 848 KB Output is correct
73 Correct 266 ms 33352 KB Output is correct
74 Correct 269 ms 33292 KB Output is correct
75 Correct 270 ms 33260 KB Output is correct
76 Correct 309 ms 33484 KB Output is correct
77 Correct 269 ms 33484 KB Output is correct
78 Correct 260 ms 33268 KB Output is correct
79 Correct 282 ms 33564 KB Output is correct
80 Correct 239 ms 33608 KB Output is correct
81 Correct 239 ms 33900 KB Output is correct
82 Correct 229 ms 33864 KB Output is correct
83 Correct 226 ms 34380 KB Output is correct
84 Correct 239 ms 34408 KB Output is correct
85 Correct 229 ms 34280 KB Output is correct
86 Correct 216 ms 34640 KB Output is correct
87 Correct 224 ms 34888 KB Output is correct
88 Correct 222 ms 35656 KB Output is correct
89 Correct 226 ms 35568 KB Output is correct
90 Correct 332 ms 34128 KB Output is correct
91 Correct 323 ms 32584 KB Output is correct
92 Correct 330 ms 32584 KB Output is correct
93 Correct 249 ms 34632 KB Output is correct
94 Correct 235 ms 33388 KB Output is correct
95 Correct 254 ms 34120 KB Output is correct
96 Correct 257 ms 33356 KB Output is correct
97 Correct 251 ms 33764 KB Output is correct
98 Correct 249 ms 33352 KB Output is correct
99 Correct 267 ms 34160 KB Output is correct
100 Correct 255 ms 33352 KB Output is correct
101 Correct 249 ms 33864 KB Output is correct
102 Correct 255 ms 33352 KB Output is correct
103 Correct 257 ms 34120 KB Output is correct
104 Correct 238 ms 33360 KB Output is correct
105 Correct 275 ms 34120 KB Output is correct
106 Correct 244 ms 33356 KB Output is correct
107 Correct 267 ms 34120 KB Output is correct
108 Correct 247 ms 33352 KB Output is correct
109 Correct 243 ms 33996 KB Output is correct
110 Correct 262 ms 33496 KB Output is correct
111 Correct 247 ms 34888 KB Output is correct
112 Correct 247 ms 33356 KB Output is correct
113 Correct 250 ms 34888 KB Output is correct
114 Correct 256 ms 33384 KB Output is correct
115 Correct 255 ms 33616 KB Output is correct
116 Correct 267 ms 33352 KB Output is correct
117 Correct 256 ms 34796 KB Output is correct
118 Correct 242 ms 33528 KB Output is correct
119 Correct 106 ms 26440 KB Output is correct
120 Correct 106 ms 26636 KB Output is correct