Submission #504015

# Submission time Handle Problem Language Result Execution time Memory
504015 2022-01-09T13:31:01 Z couplefire Snowball (JOI21_ho_t2) C++17
100 / 100
95 ms 16880 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long

const int N = 200005;

int n, q; ll a[N], w[N];
ll ld[N], rd[N], d[N], ans[N];

int main(){
    // freopen("a.in", "r", stdin);
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> q;
    for(int i = 1; i<=n; ++i)
        cin >> a[i];
    a[0] = -1e18; a[n+1] = 1e18;
    for(int i = 1; i<=q; ++i)
        cin >> w[i];
    ll cur_sum = 0;
    for(int i = 1; i<=q; ++i){
        cur_sum += w[i];
        ld[i] = max(ld[i-1], -cur_sum);
        rd[i] = max(rd[i-1], cur_sum);
    }
    for(int i = 0; i<=q; ++i)
        d[i] = ld[i]+rd[i];
    for(int i = 0; i<=n; ++i){
        int id = lower_bound(d, d+q+1, a[i+1]-a[i])-d;
        if(id==q+1){
            ans[i] += rd[q];
            ans[i+1] += ld[q];
            continue;
        }
        if(rd[id]!=rd[id-1])
            ans[i+1] += ld[id], ans[i] += a[i+1]-a[i]-ld[id];
        else ans[i] += rd[id], ans[i+1] += a[i+1]-a[i]-rd[id];
    }
    for(int i = 1; i<=n; ++i)
        cout << ans[i] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 1 ms 500 KB Output is correct
6 Correct 1 ms 452 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 440 KB Output is correct
10 Correct 1 ms 368 KB Output is correct
11 Correct 1 ms 436 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 0 ms 316 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 508 KB Output is correct
17 Correct 1 ms 520 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 1 ms 500 KB Output is correct
6 Correct 1 ms 452 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 440 KB Output is correct
10 Correct 1 ms 368 KB Output is correct
11 Correct 1 ms 436 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 0 ms 316 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 508 KB Output is correct
17 Correct 1 ms 520 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 27 ms 8636 KB Output is correct
21 Correct 29 ms 8388 KB Output is correct
22 Correct 26 ms 8248 KB Output is correct
23 Correct 22 ms 8132 KB Output is correct
24 Correct 28 ms 8664 KB Output is correct
25 Correct 89 ms 14908 KB Output is correct
26 Correct 91 ms 14904 KB Output is correct
27 Correct 90 ms 14508 KB Output is correct
28 Correct 91 ms 14644 KB Output is correct
29 Correct 93 ms 14192 KB Output is correct
30 Correct 85 ms 13632 KB Output is correct
31 Correct 77 ms 12976 KB Output is correct
32 Correct 54 ms 13228 KB Output is correct
33 Correct 9 ms 1756 KB Output is correct
34 Correct 93 ms 15336 KB Output is correct
35 Correct 92 ms 14660 KB Output is correct
36 Correct 94 ms 14892 KB Output is correct
37 Correct 95 ms 14760 KB Output is correct
38 Correct 88 ms 14532 KB Output is correct
39 Correct 91 ms 14724 KB Output is correct
40 Correct 71 ms 14712 KB Output is correct
41 Correct 32 ms 9284 KB Output is correct
42 Correct 52 ms 13168 KB Output is correct
43 Correct 76 ms 16452 KB Output is correct
44 Correct 31 ms 9128 KB Output is correct
45 Correct 69 ms 14680 KB Output is correct
46 Correct 79 ms 16572 KB Output is correct
47 Correct 74 ms 16832 KB Output is correct
48 Correct 85 ms 16880 KB Output is correct