답안 #560441

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
560441 2022-05-11T12:11:20 Z messiuuuuu Snowball (JOI21_ho_t2) C++14
0 / 100
2 ms 724 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];
map<int, bool> mp;

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

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] << ' ';
    }
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen(task".INP","r",stdin);
    //freopen(task".OUT","w",stdout);
    Input();
    Solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 380 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 392 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 2 ms 472 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Incorrect 1 ms 472 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 380 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 392 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 2 ms 472 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Incorrect 1 ms 472 KB Output isn't correct
8 Halted 0 ms 0 KB -