답안 #1006401

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1006401 2024-06-24T00:58:24 Z Joshua_Andersson Snowball (JOI21_ho_t2) C++14
100 / 100
100 ms 19000 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define int ll
const int inf = int(1e18);

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> p2;

#define rep(i, high) for (int i = 0; i < high; i++)
#define repp(i, low, high) for (int i = low; i < high; i++)
#define repe(i, container) for (auto& i : container)
#define sz(container) ((int)container.size())
#define all(x) begin(x),end(x)
#define ceildiv(x,y) (((x) + (y) - 1) / (y))

inline void fast() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); }

#if _LOCAL
#define assert(x) if (!(x)) __debugbreak()
#endif

signed main()
{
    fast();

    int n, q;
    cin >> n >> q;
    vi balls(n);
    rep(i, n) cin >> balls[i];
    vi delta(q);
    rep(i, q) cin >> delta[i];
    n += 2;
    balls.insert(balls.begin(), - inf);
    balls.push_back(inf);


    bool posfirst = delta[0] > 0;
    vi pref(delta);
    repp(i, 1, q) pref[i] += pref[i - 1];
    vi prefmax(pref);
    vi prefmin(pref);
    prefmax.insert(prefmax.begin(), 0LL);
    prefmin.insert(prefmin.begin(), 0LL);
    q++;
    repp(i, 1, q) prefmax[i] = max(prefmax[i], prefmax[i - 1]);
    repp(i, 1, q) prefmin[i] = min(prefmin[i], prefmin[i - 1]);
    delta.insert(delta.begin(), 0LL);

    repp(i, 1, n - 1)
    {
        int l = 0;
        int lo = -1;
        int hi = sz(prefmin);
        while (lo+1<hi)
        {
            int mid = (lo + hi) / 2;
            int mlo = balls[i] + prefmin[mid];
            int phi = balls[i - 1] + prefmax[mid];
            if (phi >= mlo) hi = mid;
            else lo = mid;
        }
        
        if (hi == sz(prefmin)) l = -prefmin.back();
        else
        {
            if (delta[hi] > 0) l = -prefmin[hi];
            else l = balls[i] - (balls[i-1]+prefmax[hi]);
        }

        int r = 0;
        lo = -1;
        hi = sz(prefmin);
        while (lo + 1 < hi)
        {
            int mid = (lo + hi) / 2;
            int mhi = balls[i] + prefmax[mid];
            int plo = balls[i + 1] + prefmin[mid];
            if (mhi >= plo) hi = mid;
            else lo = mid;
        }

        if (hi == sz(prefmin)) r = prefmax.back();
        else
        {
            if (delta[hi] > 0) r = (balls[i+1]+prefmin[hi]) - balls[i];
            else r = prefmax[hi];
        }
        

        cout << l + r << "\n";
    }

    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:40:10: warning: unused variable 'posfirst' [-Wunused-variable]
   40 |     bool posfirst = delta[0] > 0;
      |          ^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 356 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 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 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 356 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 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 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 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 9244 KB Output is correct
21 Correct 16 ms 9248 KB Output is correct
22 Correct 20 ms 10276 KB Output is correct
23 Correct 18 ms 10528 KB Output is correct
24 Correct 23 ms 9656 KB Output is correct
25 Correct 100 ms 17092 KB Output is correct
26 Correct 94 ms 17088 KB Output is correct
27 Correct 92 ms 15928 KB Output is correct
28 Correct 90 ms 16440 KB Output is correct
29 Correct 89 ms 15680 KB Output is correct
30 Correct 81 ms 15416 KB Output is correct
31 Correct 62 ms 15416 KB Output is correct
32 Correct 49 ms 17208 KB Output is correct
33 Correct 9 ms 1980 KB Output is correct
34 Correct 92 ms 16868 KB Output is correct
35 Correct 85 ms 15928 KB Output is correct
36 Correct 89 ms 16952 KB Output is correct
37 Correct 86 ms 16060 KB Output is correct
38 Correct 100 ms 15672 KB Output is correct
39 Correct 84 ms 15928 KB Output is correct
40 Correct 51 ms 16516 KB Output is correct
41 Correct 21 ms 12572 KB Output is correct
42 Correct 45 ms 16452 KB Output is correct
43 Correct 48 ms 17768 KB Output is correct
44 Correct 19 ms 12060 KB Output is correct
45 Correct 47 ms 16440 KB Output is correct
46 Correct 48 ms 19000 KB Output is correct
47 Correct 54 ms 18488 KB Output is correct
48 Correct 73 ms 18488 KB Output is correct