Submission #757838

# Submission time Handle Problem Language Result Execution time Memory
757838 2023-06-13T19:20:45 Z otarius Snowball (JOI21_ho_t2) C++17
100 / 100
104 ms 13416 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cstring>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair <int, int>
#define ull unsigned long long

#define int long long
// #define int unsigned long long

const ll inf = 1e18 + 7;
const ll weirdMod = 998244353;

int lft[200005], rgt[200005];
void solve() {
    int n, k;
    cin >> n >> k;
    int arr[n + 5] = {}, wnd[k + 5] = {};
    for (int i = 1; i <= n; i++)
        cin >> arr[i];
    for (int i = 1; i <= k; i++) {
        cin >> wnd[i]; wnd[i] += wnd[i - 1];
    } vector<int> vec;
    for (int i = 1; i <= k; i++) {
        lft[i] = max(lft[i - 1], wnd[i]);
        rgt[i] = max(rgt[i - 1], -wnd[i]);
    } ll ans[n + 5] = {};
    arr[0] = -inf; arr[n + 1] = inf;
    for (int i = 0; i <= n; i++) {
        if (lft[k] + rgt[k] <= arr[i + 1] - arr[i]) {
            ans[i] += lft[k]; ans[i + 1] += rgt[k]; continue;
        } int l = 1, r = k, m;
        while (l < r) {
            m = (l + r) / 2;
            if (lft[m] + rgt[m] > arr[i + 1] - arr[i])
                r = m;
            else l = m + 1;
        } while (lft[l - 1] + rgt[l - 1] > arr[i + 1] - arr[i]) l--;
        if (rgt[l] != rgt[l - 1]) {
            ans[i] += lft[l]; ans[i + 1] += arr[i + 1] - arr[i] - lft[l];
        } else {ans[i] += arr[i + 1] - arr[i] - rgt[l]; ans[i + 1] += rgt[l];}
    } for (int i = 1; i <= n; i++)
        cout << ans[i] << '\n';
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
        cout << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 360 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 464 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 360 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 464 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 27 ms 7116 KB Output is correct
21 Correct 27 ms 6856 KB Output is correct
22 Correct 25 ms 6716 KB Output is correct
23 Correct 25 ms 6616 KB Output is correct
24 Correct 38 ms 7000 KB Output is correct
25 Correct 94 ms 13244 KB Output is correct
26 Correct 94 ms 13208 KB Output is correct
27 Correct 91 ms 13004 KB Output is correct
28 Correct 98 ms 12996 KB Output is correct
29 Correct 95 ms 12636 KB Output is correct
30 Correct 92 ms 12004 KB Output is correct
31 Correct 62 ms 11480 KB Output is correct
32 Correct 56 ms 11596 KB Output is correct
33 Correct 9 ms 1632 KB Output is correct
34 Correct 94 ms 13340 KB Output is correct
35 Correct 95 ms 12992 KB Output is correct
36 Correct 104 ms 13280 KB Output is correct
37 Correct 96 ms 13004 KB Output is correct
38 Correct 99 ms 12924 KB Output is correct
39 Correct 99 ms 13024 KB Output is correct
40 Correct 76 ms 13028 KB Output is correct
41 Correct 30 ms 7616 KB Output is correct
42 Correct 58 ms 11608 KB Output is correct
43 Correct 75 ms 13208 KB Output is correct
44 Correct 31 ms 7612 KB Output is correct
45 Correct 62 ms 13100 KB Output is correct
46 Correct 78 ms 13368 KB Output is correct
47 Correct 75 ms 13416 KB Output is correct
48 Correct 76 ms 13324 KB Output is correct