Submission #870022

# Submission time Handle Problem Language Result Execution time Memory
870022 2023-11-06T16:15:40 Z Megumin2006 Snowball (JOI21_ho_t2) C++14
100 / 100
90 ms 16664 KB
#include <bits/stdc++.h>

#define int long long

using namespace std;

const int inf = 4e18;

void solve() {
    int n, q;
    cin >> n >> q;

    vector<int> a(n + 2);
    a[0] = -inf;
    a[n + 1] = inf;
    for(int i = 1; i <= n; ++i) cin >> a[i];

    priority_queue< array<int, 3>, vector< array<int, 3> >, greater< array<int, 3> > > interval;
    for(int i = 0; i <= n; ++i) {
        interval.push({a[i + 1] - a[i], i, i + 1});
    }

    int cur = 0, MaxL = 0, MaxR = 0;
    vector<int> ans(n + 2);
    for(int i = 1; i <= q; ++i) {
        int w;
        cin >> w;
        cur += w;

        MaxR = max(MaxR, cur);
        MaxL = min(MaxL, cur);

        while(1) {
            array<int, 3> fetch = interval.top();
            if (fetch[0] > MaxR - MaxL) break;

            interval.pop();
            int id1 = fetch[1], id2 = fetch[2];
            if (cur > 0) {
                ans[id1] += fetch[0] - abs(MaxL);
                ans[id2] += abs(MaxL);
            }
            else {
                ans[id1] += MaxR;
                ans[id2] += fetch[0] - MaxR;
            }
        }
    }

    while(interval.size()) {
        array<int, 3> fetch = interval.top();
        interval.pop();
        int id1 = fetch[1], id2 = fetch[2];

        ans[id1] += MaxR;
        ans[id2] += abs(MaxL);
    }

    for(int i = 1; i <= n; ++i) {
//        if (ansR[i] == -1) ansR[ fetch[1] ] = max(lastR, fetch[0] - MaxL);
        cout << ans[i] << '\n';
    }
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    if (fopen("cf.inp", "r")) {
        freopen("cf.inp", "r", stdin);
    }
    solve();
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:68:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |         freopen("cf.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 448 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 0 ms 544 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 448 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 0 ms 544 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 18 ms 2388 KB Output is correct
21 Correct 17 ms 2364 KB Output is correct
22 Correct 16 ms 2120 KB Output is correct
23 Correct 15 ms 2136 KB Output is correct
24 Correct 20 ms 3020 KB Output is correct
25 Correct 84 ms 14524 KB Output is correct
26 Correct 90 ms 13644 KB Output is correct
27 Correct 81 ms 13496 KB Output is correct
28 Correct 81 ms 13124 KB Output is correct
29 Correct 81 ms 12844 KB Output is correct
30 Correct 77 ms 13500 KB Output is correct
31 Correct 70 ms 12728 KB Output is correct
32 Correct 61 ms 13072 KB Output is correct
33 Correct 8 ms 1880 KB Output is correct
34 Correct 83 ms 13756 KB Output is correct
35 Correct 79 ms 14780 KB Output is correct
36 Correct 85 ms 14780 KB Output is correct
37 Correct 82 ms 13384 KB Output is correct
38 Correct 86 ms 13116 KB Output is correct
39 Correct 82 ms 13756 KB Output is correct
40 Correct 74 ms 14700 KB Output is correct
41 Correct 21 ms 3100 KB Output is correct
42 Correct 85 ms 12596 KB Output is correct
43 Correct 70 ms 15032 KB Output is correct
44 Correct 19 ms 2908 KB Output is correct
45 Correct 82 ms 14176 KB Output is correct
46 Correct 87 ms 16316 KB Output is correct
47 Correct 73 ms 16664 KB Output is correct
48 Correct 74 ms 16216 KB Output is correct