Submission #560459

# Submission time Handle Problem Language Result Execution time Memory
560459 2022-05-11T13:14:13 Z messiuuuuu Snowball (JOI21_ho_t2) C++14
0 / 100
2 ms 468 KB
#include<bits/stdc++.h>
#define task "C"
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define int long long
using namespace std;
const int MAXN = 2e5 + 5;
const ll INF = 1e18 + 5;

int n, q;
ll x[MAXN];

void Input()
{
    cin >> n >> q;
    for (int i = 1; i <= n; i++)
    {
        cin >> x[i];
    }
}

int cs[MAXN], l[MAXN], r[MAXN];

void Solve()
{
    x[0] = -INF;
    iota(cs + 1, cs + 1 + n, 1);
    sort(cs + 1, cs + 1 + n, [](int i, int j)
         {
             return x[i] - x[i - 1] < x[j] - x[j - 1];
         });

    int i = 1;
    ll cur = 0, maxl = INF, maxr = -INF;
    while (q-- > 0)
    {
        ll w;
        cin >> w;
        cur += w;
        maxr = max(maxr, cur);
        maxl = min(maxl, cur);
        for (; i <= n && x[cs[i]] - x[cs[i] - 1] <= maxr - maxl; i++)
        {
            if (w < 0)
            {
                r[cs[i] - 1] = x[cs[i] - 1] + maxr;
                l[cs[i]] = x[cs[i] - 1] + maxr;
            } else
            {
                r[cs[i] - 1] = x[cs[i]] + maxl;
                l[cs[i]] = x[cs[i]] + maxl;
            }
        }
    }
    for (; i <= n; i++)
    {
        r[cs[i] - 1] = x[cs[i] - 1] + maxr;
        l[cs[i]] = x[cs[i]] + maxl;
    }
    //r[cs[n]] = x[cs[n]] + maxr;
    r[n] = x[n] + maxr;
    l[1] = x[1] + maxl;

    //cout << r[1] << '\n';

    for (int i = 1; i <= n; i++)
    {
        cout << r[i] - l[i] << '\n';
    }
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen(task".INP","r",stdin);
    //freopen(task".OUT","w",stdout);
    Input();
    Solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 380 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 372 KB Output is correct
7 Incorrect 1 ms 344 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 380 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 372 KB Output is correct
7 Incorrect 1 ms 344 KB Output isn't correct
8 Halted 0 ms 0 KB -