답안 #704647

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
704647 2023-03-02T14:16:29 Z Stickfish Snowball (JOI21_ho_t2) C++17
100 / 100
224 ms 15284 KB
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

const int MAXN = 2e5 + 123;
ll a[MAXN];
ll w[MAXN];
pair<ll, ll> sg_[MAXN];
pair<ll, ll>* sg = sg_ + 1;

signed main() {
    int n, q;
    cin >> n >> q;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    for (int i = 0; i < q; ++i)
        cin >> w[i];
    ll rx = 0;
    for (int i = 0; i < q; ++i) {
        rx += w[i];
        sg[i] = sg[i - 1];
        sg[i].first = min(sg[i].first, rx);
        sg[i].second = max(sg[i].second, rx);
    }
    vector<ll> ans(n);
    ll len = sg[q - 1].second - sg[q - 1].first;
    ans[0] = -sg[q - 1].first;
    ans[n - 1] = sg[q - 1].second;
    for (int i = 0; i + 1 < n; ++i) {
        if (a[i + 1] - a[i] >= len) {
            ans[i] += sg[q - 1].second;
            ans[i + 1] += -sg[q - 1].first;
        } else {
            int lb = -1, ub = q;
            while (ub - lb > 1) {
                int mb = (lb + ub) / 2;
                if (a[i + 1] - a[i] >= sg[mb].second - sg[mb].first)
                    lb = mb;
                else
                    ub = mb;
            }
            ans[i] += sg[lb].second;
            ans[i + 1] += -sg[lb].first;
            if (w[lb + 1] > 0)
                ans[i] += a[i + 1] - a[i] - sg[lb].second + sg[lb].first;
            else
                ans[i + 1] += a[i + 1] - a[i] - sg[lb].second + sg[lb].first;
        }
    }
    for (int i = 0; i < n; ++i)
        cout << ans[i] << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 320 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 320 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 320 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 3 ms 364 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 444 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 2 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 320 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 320 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 320 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 3 ms 364 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 444 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 2 ms 324 KB Output is correct
20 Correct 78 ms 6988 KB Output is correct
21 Correct 86 ms 6912 KB Output is correct
22 Correct 71 ms 6636 KB Output is correct
23 Correct 65 ms 6492 KB Output is correct
24 Correct 73 ms 7084 KB Output is correct
25 Correct 196 ms 13340 KB Output is correct
26 Correct 195 ms 13284 KB Output is correct
27 Correct 191 ms 13036 KB Output is correct
28 Correct 210 ms 13132 KB Output is correct
29 Correct 186 ms 12656 KB Output is correct
30 Correct 173 ms 11972 KB Output is correct
31 Correct 151 ms 11468 KB Output is correct
32 Correct 133 ms 11592 KB Output is correct
33 Correct 20 ms 1596 KB Output is correct
34 Correct 203 ms 13752 KB Output is correct
35 Correct 194 ms 13180 KB Output is correct
36 Correct 199 ms 13388 KB Output is correct
37 Correct 199 ms 13148 KB Output is correct
38 Correct 183 ms 12976 KB Output is correct
39 Correct 190 ms 13212 KB Output is correct
40 Correct 182 ms 13208 KB Output is correct
41 Correct 93 ms 7628 KB Output is correct
42 Correct 133 ms 11576 KB Output is correct
43 Correct 221 ms 14904 KB Output is correct
44 Correct 93 ms 7500 KB Output is correct
45 Correct 153 ms 13060 KB Output is correct
46 Correct 223 ms 15024 KB Output is correct
47 Correct 220 ms 15196 KB Output is correct
48 Correct 224 ms 15284 KB Output is correct