Submission #621500

# Submission time Handle Problem Language Result Execution time Memory
621500 2022-08-03T22:09:52 Z elkernos Snowball (JOI21_ho_t2) C++17
100 / 100
99 ms 13740 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define x first
#define y second

int32_t main()
{
    cin.tie(0)->sync_with_stdio(0);
    int n, q;
    cin >> n >> q;
    vector<int> a(n + 1);
    vector<pair<int, int>> ord;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        if(i > 1) {
            ord.emplace_back(a[i] - a[i - 1], i);
        }
    }
    sort(ord.begin(), ord.end());
    int sum = 0, l = 0, r = 0;
    int p = 0;
    vector<int> ans(n + 1);
    while(q--) {
        int w;
        cin >> w;
        sum += w;
        if(r < sum) {
            r = sum;
            while(p < n - 1 && ord[p].x < -l + r) {
                ans[ord[p].y] += (-l);
                ans[ord[p].y - 1] += ord[p].x - (-l);
                p++;
            }
        }
        if(l > sum) {
            l = sum;
            while(p < n - 1 && ord[p].x < -l + r) {
                ans[ord[p].y - 1] += r;
                ans[ord[p].y] += ord[p].x - r;
                p++;
            }
        }
    }
    ans[1] += (-l);
    ans[n] += r;
    for(int i = p; i < (int)ord.size(); i++) {
        ans[ord[i].y - 1] += r;
        ans[ord[i].y] += (-l);
    }
    for(int i = 1; i <= n; i++) {
        cout << ans[i] << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 412 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 412 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 24 ms 2380 KB Output is correct
21 Correct 26 ms 2220 KB Output is correct
22 Correct 22 ms 1976 KB Output is correct
23 Correct 20 ms 1916 KB Output is correct
24 Correct 24 ms 2656 KB Output is correct
25 Correct 89 ms 11904 KB Output is correct
26 Correct 80 ms 11736 KB Output is correct
27 Correct 79 ms 11448 KB Output is correct
28 Correct 89 ms 11628 KB Output is correct
29 Correct 78 ms 11076 KB Output is correct
30 Correct 74 ms 10516 KB Output is correct
31 Correct 71 ms 9900 KB Output is correct
32 Correct 73 ms 10028 KB Output is correct
33 Correct 9 ms 1496 KB Output is correct
34 Correct 88 ms 12220 KB Output is correct
35 Correct 78 ms 11568 KB Output is correct
36 Correct 82 ms 11832 KB Output is correct
37 Correct 99 ms 11536 KB Output is correct
38 Correct 77 ms 11472 KB Output is correct
39 Correct 81 ms 11656 KB Output is correct
40 Correct 90 ms 11712 KB Output is correct
41 Correct 26 ms 3020 KB Output is correct
42 Correct 74 ms 10024 KB Output is correct
43 Correct 80 ms 13368 KB Output is correct
44 Correct 27 ms 2892 KB Output is correct
45 Correct 74 ms 11708 KB Output is correct
46 Correct 98 ms 13440 KB Output is correct
47 Correct 81 ms 13700 KB Output is correct
48 Correct 81 ms 13740 KB Output is correct