답안 #862049

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
862049 2023-10-17T12:45:57 Z sleepntsheep Snowball (JOI21_ho_t2) C++17
100 / 100
114 ms 11348 KB
#include <cstdio>
#include <cstring>
#include <cassert>
#include <string>
#include <deque>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <iostream>
#include <utility>
using namespace std;
using ll = long long;
using ld = long double;
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false)

#define N 200005
#define ALL(x) x.begin(), x.end()

ll n, q, x[N], w[N], hi[N], lo[N];

int main()
{
    ShinLena;
    cin >> n >> q;
    for (int i = 1; i <= n; ++i) cin >> x[i];
    for (int i = 1; i <= q; ++i) cin >> w[i], w[i] += w[i-1], hi[i] = max(hi[i-1], w[i]), lo[i] = min(lo[i-1], w[i]);

    for (int i = 1; i <= n; ++i)
    {
        ll lft= x[i], rgt=x[i];
        {
            int l = 1, r = q;
            while (l <= r)
            {
                int y = (l+r)/2;
                if (hi[y] + x[i] > lo[y] + x[i+1]) r = y - 1, rgt = max(rgt, lo[y] + x[i+1]);
                else 
                {
                    l = y + 1, rgt = max(rgt, x[i] + hi[y]);
                    //if (y < q) rgt = max(rgt, lo[y+1] + x[i+1]);
                }
            }
            if (i == n) rgt = x[i] + hi[q];
            l = 1, r = q;
            while (l <= r)
            {
                int y = (l+r)/2;
                if (lo[y] + x[i] < hi[y] + x[i-1]) r = y - 1, lft = min(lft, hi[y] + x[i-1]);
                else 
                {
                    l = y + 1, lft = min(lft, x[i] + lo[y]);
                    //if (y < q) lft = min(lft, hi[y+1] + x[i-1]);
                }
            }
            if (i == 1) lft = x[i] + lo[q];
        }
        cout << rgt - lft << '\n';
    }

    return 0;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 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 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2572 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 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 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 2 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 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 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2572 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 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 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 2 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 20 ms 6692 KB Output is correct
21 Correct 18 ms 6236 KB Output is correct
22 Correct 19 ms 6272 KB Output is correct
23 Correct 17 ms 6236 KB Output is correct
24 Correct 28 ms 7000 KB Output is correct
25 Correct 96 ms 10564 KB Output is correct
26 Correct 94 ms 10464 KB Output is correct
27 Correct 96 ms 10272 KB Output is correct
28 Correct 101 ms 10204 KB Output is correct
29 Correct 92 ms 10068 KB Output is correct
30 Correct 87 ms 9348 KB Output is correct
31 Correct 52 ms 8788 KB Output is correct
32 Correct 55 ms 9248 KB Output is correct
33 Correct 9 ms 3420 KB Output is correct
34 Correct 98 ms 10412 KB Output is correct
35 Correct 102 ms 10296 KB Output is correct
36 Correct 114 ms 10404 KB Output is correct
37 Correct 96 ms 10324 KB Output is correct
38 Correct 94 ms 10152 KB Output is correct
39 Correct 88 ms 10068 KB Output is correct
40 Correct 58 ms 10052 KB Output is correct
41 Correct 22 ms 6624 KB Output is correct
42 Correct 47 ms 8716 KB Output is correct
43 Correct 57 ms 10868 KB Output is correct
44 Correct 20 ms 6476 KB Output is correct
45 Correct 55 ms 9940 KB Output is correct
46 Correct 58 ms 11092 KB Output is correct
47 Correct 60 ms 11260 KB Output is correct
48 Correct 59 ms 11348 KB Output is correct