Submission #652625

# Submission time Handle Problem Language Result Execution time Memory
652625 2022-10-23T14:37:27 Z jerzyk Snowball (JOI21_ho_t2) C++14
100 / 100
126 ms 15308 KB
#include<bits/stdc++.h>

using namespace std;
#define nd second
#define st first
#define pb push_back
typedef long long ll;
typedef long double ld;
const int N = 200 * 1000 + 7;
ll tab[N], pr[N], mi[N], ma[N];
ll ans[N];

int BS(int a, int b, int q)
{
    int p = 0, s, k = q + 1;
    if(a > b) swap(a, b);
    while(p < k)
    {
        s = (p + k) / 2;
        if(-mi[s] + ma[s] >= tab[b] - tab[a])
            k = s;
        else
            p = s + 1;
    }
    return p;
}

void Solve()
{
    int n, q, t;
    cin >> n >> q;
    for(int i = 1; i <= n; ++i)
        cin >> tab[i];
    for(int i = 1; i <= q; ++i)
    {
        cin >> pr[i];
        pr[i] += pr[i - 1];
        ma[i] = max(ma[i - 1], pr[i]);
        mi[i] = min(mi[i - 1], pr[i]);
    }

    ans[1] += abs(mi[q]);
    for(int i = 1; i < n; ++i)
    {
        ll k = tab[i + 1], p = tab[i];
        t = BS(i, i + 1, q);
        //cout << i << " " << t << "\n";
        if(t == q + 1)
        {
            ans[i] += ma[q];
            ans[i + 1] += (-mi[q]);
            continue;
        }
        if(ma[t] == ma[t - 1])
        {
            ans[i] += ma[t];
            ans[i + 1] += (k - p) - ma[t];
        }else
        {
            ans[i + 1] += (-mi[t]);
            ans[i] += (k - p) - (-mi[t]);
        }
    }
    ans[n] += ma[q];
    for(int i = 1; i <= n; ++i)
        cout << ans[i] << "\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    Solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 396 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 472 KB Output is correct
9 Correct 1 ms 472 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 1 ms 392 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 396 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 472 KB Output is correct
9 Correct 1 ms 472 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 1 ms 392 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 29 ms 7100 KB Output is correct
21 Correct 28 ms 6952 KB Output is correct
22 Correct 27 ms 6744 KB Output is correct
23 Correct 24 ms 6604 KB Output is correct
24 Correct 29 ms 7040 KB Output is correct
25 Correct 102 ms 13448 KB Output is correct
26 Correct 99 ms 13344 KB Output is correct
27 Correct 108 ms 13072 KB Output is correct
28 Correct 96 ms 13112 KB Output is correct
29 Correct 99 ms 12664 KB Output is correct
30 Correct 107 ms 12012 KB Output is correct
31 Correct 64 ms 11428 KB Output is correct
32 Correct 57 ms 11632 KB Output is correct
33 Correct 9 ms 1620 KB Output is correct
34 Correct 99 ms 13748 KB Output is correct
35 Correct 113 ms 13220 KB Output is correct
36 Correct 125 ms 13508 KB Output is correct
37 Correct 105 ms 13124 KB Output is correct
38 Correct 104 ms 13032 KB Output is correct
39 Correct 126 ms 13176 KB Output is correct
40 Correct 73 ms 13172 KB Output is correct
41 Correct 31 ms 7696 KB Output is correct
42 Correct 77 ms 11624 KB Output is correct
43 Correct 81 ms 14900 KB Output is correct
44 Correct 33 ms 7584 KB Output is correct
45 Correct 68 ms 13076 KB Output is correct
46 Correct 85 ms 15052 KB Output is correct
47 Correct 80 ms 15308 KB Output is correct
48 Correct 79 ms 15284 KB Output is correct