Submission #1106957

# Submission time Handle Problem Language Result Execution time Memory
1106957 2024-10-31T10:03:56 Z elush None (JOI16_ho_t5) C++14
100 / 100
150 ms 14932 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 seg;
    Seg() {}
    Seg(int m) {
        for (n = 1; n < m; n <<= 1);
        seg.resize(2 * n);
    }
    void Update(int l, int r, pii x) {
        for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if (l & 1) seg[l++] += x;
            if (r & 1) seg[--r] += x;
        }
    }
    pii Query(int i) {
        pii ans = {0, 0};
        for (i += n; i; i >>= 1) ans += seg[i];
        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 <= 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 begin = 0, end = n + 1, mid;
            while (begin < end) {
                mid = (begin + end) >> 1;
                auto [a, b] = seg.Query(mid);
                if (a + b <= x[i]) begin = mid + 1;
                else end = mid;
            }
            seg.Update(0, end, {-l[i], l[i]});
        } else {
            int begin = 0, end = n + 1, mid;
            while (begin < end) {
                mid = (begin + end) >> 1;
                auto [a, b] = seg.Query(mid);
                if (a - b <= x[i]) begin = mid + 1;
                else end = mid;
            }
            seg.Update(end, n + 1, {l[i], l[i]});
        }
    }
    vi ans(n);
    for (int i = 1; i <= n; i++) ans[i - 1] = seg.Query(i).y;
    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';
}

Compilation message

2016_ho_t5.cpp: In function 'vi Solve(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
2016_ho_t5.cpp:49:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   49 |                 auto [a, b] = seg.Query(mid);
      |                      ^
2016_ho_t5.cpp:58:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   58 |                 auto [a, b] = seg.Query(mid);
      |                      ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 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 0 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 504 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 336 KB Output is correct
2 Correct 1 ms 336 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 0 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 504 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 2 ms 592 KB Output is correct
29 Correct 2 ms 592 KB Output is correct
30 Correct 2 ms 592 KB Output is correct
31 Correct 2 ms 592 KB Output is correct
32 Correct 2 ms 592 KB Output is correct
33 Correct 3 ms 592 KB Output is correct
34 Correct 2 ms 592 KB Output is correct
35 Correct 2 ms 592 KB Output is correct
36 Correct 2 ms 592 KB Output is correct
37 Correct 2 ms 592 KB Output is correct
38 Correct 2 ms 592 KB Output is correct
39 Correct 2 ms 592 KB Output is correct
40 Correct 2 ms 592 KB Output is correct
41 Correct 2 ms 592 KB Output is correct
42 Correct 2 ms 592 KB Output is correct
43 Correct 2 ms 592 KB Output is correct
44 Correct 2 ms 592 KB Output is correct
45 Correct 2 ms 592 KB Output is correct
46 Correct 2 ms 592 KB Output is correct
47 Correct 2 ms 592 KB Output is correct
48 Correct 2 ms 592 KB Output is correct
49 Correct 3 ms 592 KB Output is correct
50 Correct 2 ms 592 KB Output is correct
51 Correct 2 ms 592 KB Output is correct
52 Correct 2 ms 592 KB Output is correct
53 Correct 2 ms 592 KB Output is correct
54 Correct 2 ms 592 KB Output is correct
55 Correct 2 ms 592 KB Output is correct
56 Correct 2 ms 592 KB Output is correct
57 Correct 2 ms 592 KB Output is correct
58 Correct 2 ms 592 KB Output is correct
59 Correct 2 ms 668 KB Output is correct
60 Correct 2 ms 592 KB Output is correct
61 Correct 2 ms 664 KB Output is correct
62 Correct 2 ms 760 KB Output is correct
63 Correct 2 ms 592 KB Output is correct
64 Correct 2 ms 592 KB Output is correct
65 Correct 2 ms 592 KB Output is correct
66 Correct 2 ms 764 KB Output is correct
67 Correct 2 ms 592 KB Output is correct
68 Correct 2 ms 592 KB Output is correct
69 Correct 2 ms 592 KB Output is correct
70 Correct 1 ms 592 KB Output is correct
71 Correct 1 ms 592 KB Output is correct
72 Correct 1 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 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 0 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 504 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 2 ms 592 KB Output is correct
29 Correct 2 ms 592 KB Output is correct
30 Correct 2 ms 592 KB Output is correct
31 Correct 2 ms 592 KB Output is correct
32 Correct 2 ms 592 KB Output is correct
33 Correct 3 ms 592 KB Output is correct
34 Correct 2 ms 592 KB Output is correct
35 Correct 2 ms 592 KB Output is correct
36 Correct 2 ms 592 KB Output is correct
37 Correct 2 ms 592 KB Output is correct
38 Correct 2 ms 592 KB Output is correct
39 Correct 2 ms 592 KB Output is correct
40 Correct 2 ms 592 KB Output is correct
41 Correct 2 ms 592 KB Output is correct
42 Correct 2 ms 592 KB Output is correct
43 Correct 2 ms 592 KB Output is correct
44 Correct 2 ms 592 KB Output is correct
45 Correct 2 ms 592 KB Output is correct
46 Correct 2 ms 592 KB Output is correct
47 Correct 2 ms 592 KB Output is correct
48 Correct 2 ms 592 KB Output is correct
49 Correct 3 ms 592 KB Output is correct
50 Correct 2 ms 592 KB Output is correct
51 Correct 2 ms 592 KB Output is correct
52 Correct 2 ms 592 KB Output is correct
53 Correct 2 ms 592 KB Output is correct
54 Correct 2 ms 592 KB Output is correct
55 Correct 2 ms 592 KB Output is correct
56 Correct 2 ms 592 KB Output is correct
57 Correct 2 ms 592 KB Output is correct
58 Correct 2 ms 592 KB Output is correct
59 Correct 2 ms 668 KB Output is correct
60 Correct 2 ms 592 KB Output is correct
61 Correct 2 ms 664 KB Output is correct
62 Correct 2 ms 760 KB Output is correct
63 Correct 2 ms 592 KB Output is correct
64 Correct 2 ms 592 KB Output is correct
65 Correct 2 ms 592 KB Output is correct
66 Correct 2 ms 764 KB Output is correct
67 Correct 2 ms 592 KB Output is correct
68 Correct 2 ms 592 KB Output is correct
69 Correct 2 ms 592 KB Output is correct
70 Correct 1 ms 592 KB Output is correct
71 Correct 1 ms 592 KB Output is correct
72 Correct 1 ms 592 KB Output is correct
73 Correct 150 ms 14908 KB Output is correct
74 Correct 127 ms 14920 KB Output is correct
75 Correct 134 ms 14920 KB Output is correct
76 Correct 138 ms 14920 KB Output is correct
77 Correct 131 ms 14840 KB Output is correct
78 Correct 128 ms 14908 KB Output is correct
79 Correct 125 ms 14904 KB Output is correct
80 Correct 110 ms 14920 KB Output is correct
81 Correct 115 ms 14920 KB Output is correct
82 Correct 105 ms 14920 KB Output is correct
83 Correct 106 ms 14920 KB Output is correct
84 Correct 109 ms 14920 KB Output is correct
85 Correct 117 ms 14836 KB Output is correct
86 Correct 106 ms 14844 KB Output is correct
87 Correct 116 ms 14920 KB Output is correct
88 Correct 112 ms 14848 KB Output is correct
89 Correct 118 ms 14920 KB Output is correct
90 Correct 116 ms 14928 KB Output is correct
91 Correct 107 ms 14920 KB Output is correct
92 Correct 108 ms 14928 KB Output is correct
93 Correct 122 ms 14928 KB Output is correct
94 Correct 116 ms 14840 KB Output is correct
95 Correct 124 ms 14932 KB Output is correct
96 Correct 111 ms 14704 KB Output is correct
97 Correct 113 ms 14920 KB Output is correct
98 Correct 112 ms 14920 KB Output is correct
99 Correct 120 ms 14920 KB Output is correct
100 Correct 112 ms 14920 KB Output is correct
101 Correct 111 ms 14920 KB Output is correct
102 Correct 107 ms 14920 KB Output is correct
103 Correct 113 ms 14920 KB Output is correct
104 Correct 114 ms 14920 KB Output is correct
105 Correct 108 ms 14924 KB Output is correct
106 Correct 124 ms 14920 KB Output is correct
107 Correct 110 ms 14892 KB Output is correct
108 Correct 108 ms 14920 KB Output is correct
109 Correct 115 ms 14928 KB Output is correct
110 Correct 109 ms 14932 KB Output is correct
111 Correct 107 ms 14928 KB Output is correct
112 Correct 99 ms 14916 KB Output is correct
113 Correct 108 ms 14920 KB Output is correct
114 Correct 105 ms 14928 KB Output is correct
115 Correct 103 ms 14908 KB Output is correct
116 Correct 101 ms 14836 KB Output is correct
117 Correct 110 ms 14908 KB Output is correct
118 Correct 104 ms 14920 KB Output is correct
119 Correct 16 ms 10064 KB Output is correct
120 Correct 13 ms 10232 KB Output is correct