Submission #862050

# Submission time Handle Problem Language Result Execution time Memory
862050 2023-10-17T12:46:48 Z sleepntsheep Snowball (JOI21_ho_t2) C++17
100 / 100
98 ms 6740 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], hi[N], lo[N];

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

    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 (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 (i == 1) lft = x[i] + lo[q];
        }
        cout << rgt - lft << '\n';
    }

    return 0;
}


# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 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 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 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 2392 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 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 0 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 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 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 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 2392 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 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 0 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 18 ms 4700 KB Output is correct
21 Correct 19 ms 4636 KB Output is correct
22 Correct 16 ms 4700 KB Output is correct
23 Correct 16 ms 4700 KB Output is correct
24 Correct 22 ms 4732 KB Output is correct
25 Correct 98 ms 6488 KB Output is correct
26 Correct 94 ms 6496 KB Output is correct
27 Correct 97 ms 6480 KB Output is correct
28 Correct 97 ms 6484 KB Output is correct
29 Correct 94 ms 6228 KB Output is correct
30 Correct 89 ms 5804 KB Output is correct
31 Correct 52 ms 5484 KB Output is correct
32 Correct 45 ms 5372 KB Output is correct
33 Correct 10 ms 2904 KB Output is correct
34 Correct 96 ms 6740 KB Output is correct
35 Correct 95 ms 6352 KB Output is correct
36 Correct 94 ms 6736 KB Output is correct
37 Correct 96 ms 6424 KB Output is correct
38 Correct 93 ms 6480 KB Output is correct
39 Correct 88 ms 6484 KB Output is correct
40 Correct 56 ms 6484 KB Output is correct
41 Correct 19 ms 4700 KB Output is correct
42 Correct 48 ms 5524 KB Output is correct
43 Correct 56 ms 6736 KB Output is correct
44 Correct 21 ms 4688 KB Output is correct
45 Correct 50 ms 6356 KB Output is correct
46 Correct 56 ms 6740 KB Output is correct
47 Correct 58 ms 6600 KB Output is correct
48 Correct 57 ms 6612 KB Output is correct