Submission #413379

# Submission time Handle Problem Language Result Execution time Memory
413379 2021-05-28T15:37:12 Z egorlifar Snowball (JOI21_ho_t2) C++17
100 / 100
161 ms 17880 KB
/*
KAMUI!
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ 
▓▓▓▓▓▓▓▓▓▓▓▓▓██████████▓▓▓▓▓▓▓▓▓▓▓▓▓▓ 
▓▓▓▓▓▓▓▓▓▓███▓▓▓▓▓▓▓▓▓▓█████▓▓▓▓▓▓▓▓▓
▓▓▓▓▓▓▓███▓▒▒░▒▒▒▒▒░░░▒▒▒▓▓███▓▓▓▓▓▓▓ 
▓▓▓▓▓▓█▓▒▒▒▓▓████████▓▒▒░▒▒▒▓██▓▓▓▓▓▓
▓▓▓▓██▒▓████████████████▓░▒▒▒▒▓██▓▓▓▓ 
▓▓▓██▓███████▓▒░░░░░░░▒███▒░░▒▒▒██▓▓▓ 
▓▓█████████▓░░░░░░░░░░░░░██▓▓██████▓▓ 
▓▓█▒▓███████████▓▓▒▒▒▓▓██████████▓█▓▓ 
▓██▒▒▒███████████████████████████▓▓█▓ 
▓█▓▒▒░░████████▒░░░░▓███████████▓░▒█▓ 
▓█▒▒▒░██░▒████░░░░░░█████░░████▓░░▒█▓ 
▓█▒▒▒▒██░░░██▓░░░░░░░███▒░░████▒▒▒▒█▓ 
▓█▓▒▒▒██▒░░░▓█▓░░░░░▓█▓░░░▓███▓▒▒░▓█▓ 
▓█▓▒▒▒███░░░░████████▓░░░░░████▒▒▒▓█▓ 
▓▓█▒▒░▓███░░░▒███████▒░░░▒███▓▒▒▒▒█▓▓ 
▓▓██▒▒░████▒░░███████░░░▓███▓░▒▒▒██▓▓ 
▓▓▓██▒▒▒█████▓░░██████▒▓███▓▒░▒▒██▓▓▓ 
▓▓▓▓██▓▒░▓██████████████▓▒░▒▒▒▓██▓▓▓▓ 
▓▓▓▓▓▓██▓░▒▓█████████▒░░▒▒▒▒▓██▓▓▓▓▓▓ 
▓▓▓▓▓▓▓███▓▒▒▓██████▓░▒▒▒▓▓███▓▓▓▓▓▓▓ 
▓▓▓▓▓▓▓▓▓▓▓███▓▓▓▓███▓▓▓████▓▓▓▓▓▓▓▓▓ 
▓▓▓▓▓▓▓▓▓▓▓▓▓███████████▓▓▓▓▓▓▓▓▓▓▓▓▓ 
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
*/
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
 
using namespace std;
template<typename T1, typename T2> inline void chkmin(T1 &a, T2 b) {if (a > b) a = b;}
template<typename T1, typename T2> inline void chkmax(T1 &a, T2 b) {if (a < b) a = b;}
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define left left228
#define right right228
#define y1 y1228
#define mp make_pair
#define pb push_back
#define y2 y2228
#define rank rank228
using ll = long long;
using ld = long double; 
const string FILENAME = "input";
const int Mod = 1000000007;


int sum(int a, int b) {
    return (a + b >= Mod ? a + b - Mod: a + b);
}


int mul(int a, int b) {
    return ((ll)a * b) % Mod;
}


int powm(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1) {
            res = mul(res, a);
        }
        a = mul(a, a);
        b >>= 1;
    }
    return res;
}


int inv(int a) {
    return powm(a, Mod - 2);
}


const int MAXN = 200229;


int n, q;
ll x[MAXN];
ll val[MAXN];


void solve() {
    cin >> n >> q;
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    ll sum = 0;
    ll kek = 0;
    ll kek1 = 0;
    vector<pair<ll, ll> > ste, ste1;
    for (int it = 0; it < q; it++) {
        ll shift;
        cin >> shift;
        sum += shift;
        if (sum > kek) {
            ste1.pb(mp(sum, -kek1));
        }
        if (sum < kek1) {
            ste.pb(mp(-sum, kek));
        }
        chkmax(kek, sum);
        chkmin(kek1, sum);
    }
    vector<pair<ll, int> > st, st1;
    for (int i = 0; i < n; i++) {
        ll add = 0;
        if (i == 0) {
            add += abs(kek1);
        } else {
            st.pb(mp(x[i] - x[i - 1], i));
        }
        if (i == n - 1) {
            add += abs(kek);
        } else {
            st1.pb(mp(x[i + 1] - x[i], i));
        }
        val[i] = add;
    }
    sort(all(st));
    sort(all(st1));
    int uk = 0;
    ll fk = 0;
    for (auto x: st) {
        while (uk < sz(ste)) {
            ll val = ste[uk].first + ste[uk].second;
            if (val <= x.first) {
                chkmax(fk, ste[uk].first);
                uk++;
            } else {
                break;
            }
        }
        if (uk != sz(ste)) {
            ll g = x.first - ste[uk].second;
            ll fk1 = max(min(fk, x.first), g);
            val[x.second] += fk1;
        } else {
            val[x.second] += min(fk, x.first);
        }
    }
    uk = 0;
    fk = 0;
    for (auto x: st1) {
        while (uk < sz(ste1)) {
            ll val = ste1[uk].first + ste1[uk].second;
            if (val <= x.first) {
                chkmax(fk, ste1[uk].first);
                uk++;
            } else {
                break;
            }
        }
        if (uk != sz(ste1)) {
            ll g = x.first - ste1[uk].second;
            ll fk1 = max(min(fk, x.first), g);
            val[x.second] += fk1;
        } else {
            val[x.second] += min(fk, x.first);
        }
    }
    for (int i = 0; i < n; i++) {
        cout << val[i] << '\n';
    }
}
//21:50

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   // read(FILENAME);
    int t;
    t = 1;
  //  cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
 
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 3 ms 460 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 3 ms 460 KB Output is correct
16 Correct 2 ms 460 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 3 ms 460 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 3 ms 460 KB Output is correct
16 Correct 2 ms 460 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 45 ms 3492 KB Output is correct
21 Correct 39 ms 3556 KB Output is correct
22 Correct 41 ms 3584 KB Output is correct
23 Correct 32 ms 3656 KB Output is correct
24 Correct 39 ms 5192 KB Output is correct
25 Correct 150 ms 17772 KB Output is correct
26 Correct 161 ms 17704 KB Output is correct
27 Correct 138 ms 17384 KB Output is correct
28 Correct 127 ms 17104 KB Output is correct
29 Correct 133 ms 12324 KB Output is correct
30 Correct 123 ms 10704 KB Output is correct
31 Correct 130 ms 10264 KB Output is correct
32 Correct 115 ms 10320 KB Output is correct
33 Correct 13 ms 1864 KB Output is correct
34 Correct 126 ms 11628 KB Output is correct
35 Correct 126 ms 11592 KB Output is correct
36 Correct 128 ms 17648 KB Output is correct
37 Correct 152 ms 16736 KB Output is correct
38 Correct 129 ms 17272 KB Output is correct
39 Correct 154 ms 17376 KB Output is correct
40 Correct 130 ms 17256 KB Output is correct
41 Correct 36 ms 4472 KB Output is correct
42 Correct 115 ms 10320 KB Output is correct
43 Correct 106 ms 17820 KB Output is correct
44 Correct 38 ms 3632 KB Output is correct
45 Correct 146 ms 17336 KB Output is correct
46 Correct 120 ms 17880 KB Output is correct
47 Correct 116 ms 15768 KB Output is correct
48 Correct 119 ms 15632 KB Output is correct