Submission #936915

# Submission time Handle Problem Language Result Execution time Memory
936915 2024-03-03T03:17:55 Z emanIaicepsa Snowball (JOI21_ho_t2) C++14
100 / 100
110 ms 15428 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define dbg(...) cerr<<#__VA_ARGS__<<" = ";_do(__VA_ARGS__);
template<typename T> void _do(T x){cerr<<x<<"\n";}
template<typename T,typename ...U> void _do(T x,U ...y){cerr<<x<<", ";_do(y...);}

signed main(){
    ios::sync_with_stdio(0), cin.tie(0);
    int N, Q;
    cin >> N >> Q;
    vector<ll> arr(N + 2), ansR(N + 2), ansL(N + 2);
    arr[0] = -1e18, arr[N + 1] = 1e18;
    for (int i = 1; i <= N; i++) cin >> arr[i];

    vector<pair<ll, int>> difL, difR;
    for (int i = 1; i <= N; i++) {
        difL.push_back({arr[i - 1] - arr[i], i});
        difR.push_back({arr[i + 1] - arr[i], i});
    }

    sort(difL.begin(), difL.end(), greater<pair<ll, int>>());
    sort(difR.begin(), difR.end());
    
    vector<ll> ope(Q);
    for (auto &i: ope) cin >> i;
    
    ll maxR = 0, minL = 0, cur = 0;

    int ridx = 0, lidx = 0;

    for (int i = 0; i < Q; i++) {
        cur += ope[i];

        if (cur > maxR) {
            while (ridx < N && difR[ridx].first + minL < cur) {
                ansR[difR[ridx].second] += maxR;
                ansR[difR[ridx].second] += max(0LL, difR[ridx].first + minL - maxR);
                ridx++;
            }
            maxR = cur;
        }

        if (cur < minL) {
            while (lidx < N && difL[lidx].first + maxR > cur) {
                ansL[difL[lidx].second] -= minL;
                ansL[difL[lidx].second] -= min(0LL, difL[lidx].first + maxR - minL);
                lidx++;
            }
            minL = cur;
        }
    }

    while (ridx < N) {
        ansR[difR[ridx].second] += maxR;
        ridx++;
    }

    while (lidx < N) {
        ansL[difL[lidx].second] -= minL;
        lidx++;
    }

    for (int i = 1; i <= N; i++) {
        // dbg(i, ansL[i], ansR[i]);
        cout << ansL[i] + ansR[i] << '\n';
    }


}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 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 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 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 348 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 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 20 ms 1884 KB Output is correct
21 Correct 19 ms 1880 KB Output is correct
22 Correct 18 ms 1884 KB Output is correct
23 Correct 17 ms 2176 KB Output is correct
24 Correct 21 ms 3364 KB Output is correct
25 Correct 81 ms 14504 KB Output is correct
26 Correct 82 ms 15260 KB Output is correct
27 Correct 82 ms 14920 KB Output is correct
28 Correct 82 ms 15188 KB Output is correct
29 Correct 96 ms 14504 KB Output is correct
30 Correct 83 ms 13704 KB Output is correct
31 Correct 77 ms 13488 KB Output is correct
32 Correct 51 ms 13384 KB Output is correct
33 Correct 8 ms 1752 KB Output is correct
34 Correct 82 ms 14532 KB Output is correct
35 Correct 79 ms 15008 KB Output is correct
36 Correct 83 ms 15012 KB Output is correct
37 Correct 87 ms 14780 KB Output is correct
38 Correct 85 ms 15428 KB Output is correct
39 Correct 86 ms 14768 KB Output is correct
40 Correct 84 ms 14756 KB Output is correct
41 Correct 19 ms 1880 KB Output is correct
42 Correct 73 ms 13956 KB Output is correct
43 Correct 74 ms 14760 KB Output is correct
44 Correct 19 ms 1884 KB Output is correct
45 Correct 110 ms 14288 KB Output is correct
46 Correct 67 ms 15100 KB Output is correct
47 Correct 71 ms 14952 KB Output is correct
48 Correct 68 ms 14784 KB Output is correct