Submission #957878

# Submission time Handle Problem Language Result Execution time Memory
957878 2024-04-04T12:43:50 Z peterandvoi Snowball (JOI21_ho_t2) C++17
100 / 100
80 ms 14268 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef ngu
#include "debug.h"
#else
#define debug(...) 42
#endif

const int N = (int) 2e5 + 5;
const long long INF = (long long) 1e18;

int n, q;
long long a[N], res[N];

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    #ifdef ngu
    freopen("test.inp", "r", stdin);
    freopen("test.out", "w", stdout);
    #endif
    cin >> n >> q;
    a[0] = -INF;
    a[n + 1] = INF;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    vector<pair<long long, int>> delta;
    for (int i = 0; i <= n; ++i) {
        delta.emplace_back(a[i + 1] - a[i], i);
    }
    sort(delta.rbegin(), delta.rend());
    long long cur = 0, L = 0, R = 0;
    for (int i = 1; i <= q; ++i) {
        long long x;
        cin >> x;
        cur += x;
        if (x > 0) {
            R = max(R, cur);
            while (delta.size() && delta.back().first <= L + R) {
                auto [v, id] = delta.back();
                res[id] += v - L;
                res[id + 1] += L;
                delta.pop_back();
            }
        } else {
            L = max(L, -cur);
            while (delta.size() && delta.back().first <= L + R) {
                auto [v, id] = delta.back();
                res[id] += R;
                res[id + 1] += v - R;
                delta.pop_back();
            }
        }
    }
    while (delta.size()) {
        auto [v, id] = delta.back();
        res[id] += R;
        res[id + 1] += L;
        delta.pop_back();
    }
    for (int i = 1; i <= n; ++i) {
        cout << res[i] << "\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2552 KB Output is correct
4 Correct 2 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2524 KB Output is correct
7 Correct 2 ms 2396 KB Output is correct
8 Correct 1 ms 2548 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2472 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 2 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 2 ms 2520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2552 KB Output is correct
4 Correct 2 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2524 KB Output is correct
7 Correct 2 ms 2396 KB Output is correct
8 Correct 1 ms 2548 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2472 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 2 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 2 ms 2520 KB Output is correct
20 Correct 19 ms 4444 KB Output is correct
21 Correct 17 ms 4444 KB Output is correct
22 Correct 16 ms 4176 KB Output is correct
23 Correct 17 ms 4176 KB Output is correct
24 Correct 20 ms 4908 KB Output is correct
25 Correct 65 ms 11972 KB Output is correct
26 Correct 69 ms 12160 KB Output is correct
27 Correct 67 ms 12060 KB Output is correct
28 Correct 61 ms 12224 KB Output is correct
29 Correct 60 ms 11608 KB Output is correct
30 Correct 59 ms 11148 KB Output is correct
31 Correct 64 ms 11428 KB Output is correct
32 Correct 62 ms 12388 KB Output is correct
33 Correct 8 ms 3648 KB Output is correct
34 Correct 64 ms 12292 KB Output is correct
35 Correct 59 ms 11944 KB Output is correct
36 Correct 80 ms 12480 KB Output is correct
37 Correct 60 ms 12380 KB Output is correct
38 Correct 63 ms 11708 KB Output is correct
39 Correct 63 ms 12196 KB Output is correct
40 Correct 72 ms 11832 KB Output is correct
41 Correct 27 ms 5200 KB Output is correct
42 Correct 54 ms 12216 KB Output is correct
43 Correct 51 ms 13440 KB Output is correct
44 Correct 21 ms 5064 KB Output is correct
45 Correct 61 ms 12992 KB Output is correct
46 Correct 57 ms 14268 KB Output is correct
47 Correct 58 ms 14012 KB Output is correct
48 Correct 64 ms 14264 KB Output is correct