답안 #560463

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
560463 2022-05-11T13:26:19 Z messiuuuuu Snowball (JOI21_ho_t2) C++14
100 / 100
144 ms 13780 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 = 0, maxr = 0;
    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[2] << '\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();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 332 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 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 332 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 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 41 ms 2360 KB Output is correct
21 Correct 26 ms 2260 KB Output is correct
22 Correct 26 ms 1996 KB Output is correct
23 Correct 33 ms 1868 KB Output is correct
24 Correct 33 ms 2680 KB Output is correct
25 Correct 103 ms 11796 KB Output is correct
26 Correct 86 ms 11816 KB Output is correct
27 Correct 99 ms 11396 KB Output is correct
28 Correct 110 ms 11724 KB Output is correct
29 Correct 91 ms 11088 KB Output is correct
30 Correct 91 ms 10424 KB Output is correct
31 Correct 65 ms 9860 KB Output is correct
32 Correct 58 ms 10100 KB Output is correct
33 Correct 12 ms 1536 KB Output is correct
34 Correct 101 ms 12316 KB Output is correct
35 Correct 90 ms 11528 KB Output is correct
36 Correct 93 ms 11760 KB Output is correct
37 Correct 112 ms 11540 KB Output is correct
38 Correct 116 ms 11412 KB Output is correct
39 Correct 108 ms 11776 KB Output is correct
40 Correct 80 ms 11640 KB Output is correct
41 Correct 34 ms 3008 KB Output is correct
42 Correct 79 ms 10080 KB Output is correct
43 Correct 85 ms 13404 KB Output is correct
44 Correct 32 ms 2896 KB Output is correct
45 Correct 92 ms 11572 KB Output is correct
46 Correct 85 ms 13436 KB Output is correct
47 Correct 144 ms 13720 KB Output is correct
48 Correct 93 ms 13780 KB Output is correct