Submission #935083

# Submission time Handle Problem Language Result Execution time Memory
935083 2024-02-28T15:10:42 Z haxorman Snowball (JOI21_ho_t2) C++14
100 / 100
86 ms 14272 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int mxN = 2e5 + 7;

int arr[mxN], ans[mxN];

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int n, q;
    cin >> n >> q;
    
    vector<pair<int,int>> dist;
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];

        if (i && abs(arr[i] - arr[i-1])) {
            dist.push_back({abs(arr[i] - arr[i-1]), i-1});
        }
    }
    sort(dist.begin(), dist.end(), greater<pair<int,int>>());

    int l = 0, r = 0, cur = 0, val = INT_MIN;
    for (int i = 0; i < q; ++i) {
        int w;
        cin >> w;

        cur += w;
        l = min(l, cur);
        r = max(r, cur);
    
        while (dist.size() && abs(l) + r >= dist.back().first) {
            auto [d, id] = dist.back();
            dist.pop_back();

            //cout << d << ' ' << id << ' ' << l << ' ' << r << ' ' << w << '\n';

            if (w>=0) {
                ans[id] += d-abs(l);
                ans[id+1] += abs(l);
            }
            else {
                ans[id+1] += d-r;
                ans[id] += r;
            }
        }
    }

    ans[0] += abs(l), ans[n-1] += r;
    while (dist.size()) {
        auto [d, id] = dist.back();
        dist.pop_back();
        
        ans[id] += r, ans[id+1] += abs(l);
    }
    
    for (int i = 0; i < n; ++i) {
        cout << ans[i] << "\n";
    }
}

Compilation message

Main.cpp: In function 'int32_t main()':
Main.cpp:36:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   36 |             auto [d, id] = dist.back();
      |                  ^
Main.cpp:54:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   54 |         auto [d, id] = dist.back();
      |              ^
Main.cpp:26:32: warning: unused variable 'val' [-Wunused-variable]
   26 |     int l = 0, r = 0, cur = 0, val = INT_MIN;
      |                                ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2612 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 2 ms 2392 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 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 2 ms 2520 KB Output is correct
16 Correct 2 ms 2408 KB Output is correct
17 Correct 2 ms 2652 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2612 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 2 ms 2392 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 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 2 ms 2520 KB Output is correct
16 Correct 2 ms 2408 KB Output is correct
17 Correct 2 ms 2652 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 19 ms 4444 KB Output is correct
21 Correct 26 ms 4444 KB Output is correct
22 Correct 25 ms 4180 KB Output is correct
23 Correct 24 ms 4188 KB Output is correct
24 Correct 20 ms 4820 KB Output is correct
25 Correct 60 ms 11968 KB Output is correct
26 Correct 66 ms 11956 KB Output is correct
27 Correct 67 ms 11656 KB Output is correct
28 Correct 73 ms 11700 KB Output is correct
29 Correct 60 ms 11196 KB Output is correct
30 Correct 58 ms 11204 KB Output is correct
31 Correct 56 ms 10116 KB Output is correct
32 Correct 45 ms 10392 KB Output is correct
33 Correct 7 ms 3544 KB Output is correct
34 Correct 61 ms 12300 KB Output is correct
35 Correct 63 ms 12444 KB Output is correct
36 Correct 62 ms 12040 KB Output is correct
37 Correct 69 ms 11700 KB Output is correct
38 Correct 72 ms 11712 KB Output is correct
39 Correct 61 ms 11968 KB Output is correct
40 Correct 86 ms 12220 KB Output is correct
41 Correct 28 ms 5204 KB Output is correct
42 Correct 53 ms 10208 KB Output is correct
43 Correct 52 ms 13500 KB Output is correct
44 Correct 19 ms 4956 KB Output is correct
45 Correct 60 ms 12740 KB Output is correct
46 Correct 59 ms 14272 KB Output is correct
47 Correct 86 ms 14012 KB Output is correct
48 Correct 58 ms 13888 KB Output is correct