답안 #1092276

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1092276 2024-09-23T16:48:05 Z ortsac Snowball (JOI21_ho_t2) C++17
100 / 100
185 ms 13752 KB
#include <bits/stdc++.h>
 
using namespace std;

#define int long long


int INF = 0x3f3f3f3f3f3f3f3f;
vector<int> mx, mi;

bool check(int a, int b, int q) {
    int la = (a + mi[q]), ra = (a + mx[q]);
    int lb = (b + mi[q]), rb = (b + mx[q]);
    if ((la <= lb) && (lb <= ra)) return 1;
    if ((lb <= la) && (la <= rb)) return 1;
    return 0;
}

int32_t main() {
    int n, q;
    cin >> n >> q;
    vector<int> v(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> v[i];
    }
    int curr = 0;
    mx.resize(q + 1);
    mi.resize(q + 1);
    vector<int> x(q + 1);
    for (int i = 1; i <= q; i++) {
        cin >> x[i];
        curr += x[i];
        mx[i] = max(mx[i - 1], curr);
        mi[i] = min(mi[i - 1], curr);
    }
    for (int i = 1; i <= n; i++) {
        int left = q + 1, right = q + 1;
        if (i > 1) {
            int l = 0, r = q, ans = q + 1;
            while (l <= r) {
                int m = (l+r)/2;
                if (check(v[i - 1], v[i], m)) {
                    ans = m;
                    r = m - 1;
                } else {
                    l = m + 1;
                }
            }
            left = ans;
        }
        if (i < n) {
            int l = 0, r = q, ans = q + 1;
            while (l <= r) {
                int m = (l+r)/2;
                if (check(v[i], v[i + 1], m)) {
                    ans = m;
                    r = m - 1;
                } else {
                    l = m + 1;
                }
            }
            right = ans;
        }
        int amntl, amntr;
        // calc amntl
        if (left == (q + 1)) {
            amntl = abs(mi[q]);
        } else {
            if (x[left] > 0) {
                amntl = abs(mi[left - 1]);
            } else {
                amntl = abs(v[i] - (v[i - 1] + mx[left - 1]));
            }
        }
        // calc amntr
        if (right == (q + 1)) {
            amntr = abs(mx[q]);
        } else {
            if (x[right] < 0) {
                amntr = abs(mx[right - 1]);
            } else {
                amntr = abs((v[i + 1] + mi[right - 1]) - v[i]);
            }
        }
        // cout
        int amnt = 0;
        amnt += amntl;
        amnt += amntr;
        //cout << amntl << " " << amntr << "\n";
        cout << amnt << "\n";
    }
}
# 결과 실행 시간 메모리 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 2 ms 348 KB Output is correct
5 Correct 2 ms 448 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 2 ms 480 KB Output is correct
9 Correct 2 ms 484 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 2 ms 372 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 2 ms 344 KB Output is correct
# 결과 실행 시간 메모리 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 2 ms 348 KB Output is correct
5 Correct 2 ms 448 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 2 ms 480 KB Output is correct
9 Correct 2 ms 484 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 2 ms 372 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 2 ms 344 KB Output is correct
20 Correct 57 ms 7156 KB Output is correct
21 Correct 53 ms 7000 KB Output is correct
22 Correct 49 ms 6780 KB Output is correct
23 Correct 45 ms 6684 KB Output is correct
24 Correct 56 ms 6996 KB Output is correct
25 Correct 179 ms 11860 KB Output is correct
26 Correct 179 ms 11856 KB Output is correct
27 Correct 171 ms 11604 KB Output is correct
28 Correct 174 ms 11600 KB Output is correct
29 Correct 174 ms 11088 KB Output is correct
30 Correct 162 ms 10576 KB Output is correct
31 Correct 107 ms 10064 KB Output is correct
32 Correct 105 ms 10176 KB Output is correct
33 Correct 17 ms 1628 KB Output is correct
34 Correct 179 ms 12352 KB Output is correct
35 Correct 173 ms 11720 KB Output is correct
36 Correct 185 ms 11836 KB Output is correct
37 Correct 175 ms 11604 KB Output is correct
38 Correct 181 ms 11604 KB Output is correct
39 Correct 169 ms 11600 KB Output is correct
40 Correct 129 ms 11588 KB Output is correct
41 Correct 64 ms 7764 KB Output is correct
42 Correct 108 ms 10064 KB Output is correct
43 Correct 149 ms 13396 KB Output is correct
44 Correct 69 ms 7504 KB Output is correct
45 Correct 126 ms 11672 KB Output is correct
46 Correct 151 ms 13648 KB Output is correct
47 Correct 166 ms 13652 KB Output is correct
48 Correct 153 ms 13752 KB Output is correct