Submission #912427

# Submission time Handle Problem Language Result Execution time Memory
912427 2024-01-19T12:50:59 Z andrei_iorgulescu Snowball (JOI21_ho_t2) C++14
100 / 100
77 ms 15524 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

int inf = 1e18;

int n,q,a[200005];
int minwind = 0,maxwind = 0,wind = 0;
int lexp[200005],rexp[200005];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> q;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= n; i++)
        lexp[i] = rexp[i] = inf;
    vector<pair<int,int>>difs;
    for (int i = 1; i < n; i++)
        difs.push_back({a[i + 1] - a[i],i});
    sort(difs.begin(),difs.end());
    reverse(difs.begin(),difs.end());
    for (int i = 1; i <= q; i++)
    {
        int x;
        cin >> x;
        wind += x;
        int mx = max(maxwind,wind);
        int mn = min(minwind,wind);
        int cur = mx - mn;
        while (!difs.empty() and difs.back().first <= cur)
        {
            int pos = difs.back().second;
            difs.pop_back();
            int extr = a[pos] + maxwind,extl = a[pos + 1] + minwind;
            if (wind > 0)
            {
                lexp[pos + 1] = a[pos + 1] + minwind;
                rexp[pos] = lexp[pos + 1];
            }
            else
            {
                rexp[pos] = a[pos] + maxwind;
                lexp[pos + 1] = rexp[pos];
            }
        }
        maxwind = mx;
        minwind = mn;
    }
    for (int i = 1; i <= n; i++)
    {
        if (lexp[i] == inf)
            lexp[i] = a[i] + minwind;
        if (rexp[i] == inf)
            rexp[i] = a[i] + maxwind;
    }
    for (int i = 1; i <= n; i++)
        cout << rexp[i] - lexp[i] << '\n';
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:40:17: warning: unused variable 'extr' [-Wunused-variable]
   40 |             int extr = a[pos] + maxwind,extl = a[pos + 1] + minwind;
      |                 ^~~~
Main.cpp:40:41: warning: unused variable 'extl' [-Wunused-variable]
   40 |             int extr = a[pos] + maxwind,extl = a[pos + 1] + minwind;
      |                                         ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4512 KB Output is correct
4 Correct 2 ms 4700 KB Output is correct
5 Correct 2 ms 4700 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 2 ms 4440 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
11 Correct 2 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 2 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 2 ms 4700 KB Output is correct
16 Correct 2 ms 4700 KB Output is correct
17 Correct 2 ms 4696 KB Output is correct
18 Correct 2 ms 4444 KB Output is correct
19 Correct 2 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4512 KB Output is correct
4 Correct 2 ms 4700 KB Output is correct
5 Correct 2 ms 4700 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 2 ms 4440 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
11 Correct 2 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 2 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 2 ms 4700 KB Output is correct
16 Correct 2 ms 4700 KB Output is correct
17 Correct 2 ms 4696 KB Output is correct
18 Correct 2 ms 4444 KB Output is correct
19 Correct 2 ms 4444 KB Output is correct
20 Correct 19 ms 6584 KB Output is correct
21 Correct 18 ms 6492 KB Output is correct
22 Correct 17 ms 6232 KB Output is correct
23 Correct 17 ms 6236 KB Output is correct
24 Correct 20 ms 6864 KB Output is correct
25 Correct 64 ms 13504 KB Output is correct
26 Correct 66 ms 13404 KB Output is correct
27 Correct 77 ms 13768 KB Output is correct
28 Correct 65 ms 13048 KB Output is correct
29 Correct 68 ms 13512 KB Output is correct
30 Correct 61 ms 12744 KB Output is correct
31 Correct 59 ms 13020 KB Output is correct
32 Correct 45 ms 12428 KB Output is correct
33 Correct 8 ms 5600 KB Output is correct
34 Correct 75 ms 13744 KB Output is correct
35 Correct 74 ms 13048 KB Output is correct
36 Correct 65 ms 14008 KB Output is correct
37 Correct 64 ms 13052 KB Output is correct
38 Correct 66 ms 12916 KB Output is correct
39 Correct 64 ms 13240 KB Output is correct
40 Correct 69 ms 13736 KB Output is correct
41 Correct 20 ms 7232 KB Output is correct
42 Correct 66 ms 12600 KB Output is correct
43 Correct 60 ms 14856 KB Output is correct
44 Correct 20 ms 7160 KB Output is correct
45 Correct 61 ms 12988 KB Output is correct
46 Correct 59 ms 14812 KB Output is correct
47 Correct 62 ms 15000 KB Output is correct
48 Correct 62 ms 15524 KB Output is correct