Submission #378360

# Submission time Handle Problem Language Result Execution time Memory
378360 2021-03-16T14:47:35 Z smjleo Snowball (JOI21_ho_t2) C++14
100 / 100
116 ms 11216 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define int long long
#define nl '\n'
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
mt19937 rng((unsigned)chrono::steady_clock::now().time_since_epoch().count());
const int mod = 1000000007, mod2 = 998244353;

// change this
const int N = 200005;

int n, q, x[N], w, ans[N];

signed main() {
    io;
    // cout << "COMPILED" << endl;
    cin >> n >> q;
    vector< pair<int, pair<int, int> > > inter;
    for (int i=0; i<n; i++) {
        cin >> x[i];
        if (i) inter.push_back({x[i] - x[i-1], {i-1, i}});
    }

    sort(inter.begin(), inter.end());
    int l = 0, r = 0, d = 0, j = 0, m = inter.size();

    for (int i=0; i<q; i++) {
        cin >> w;
        d += w;
        int lo = l, ro = r; // old ones before we change
        l = max(l, -d), r = max(r, d);
        // cout << l << ' ' << r << endl;
        // we can move at most r to the right and at most l to the left
        
        while (j < m && inter[j].first < l + r) {
            // this interval exceeds movement
            // ok lets handle this
            if (r > ro) {
                // r increased
                // cout << inter[j].second.first << ' ' << inter[j].first - lo << ' ' << lo << endl;
                ans[inter[j].second.second] += lo; // has to be same as old l
                ans[inter[j].second.first] += inter[j].first - lo;   // take remaining
            } else {
                // l increased
                // cout << inter[j].second.first << ' ' << ro << ' ' << inter[j].first - ro << endl;
                ans[inter[j].second.first] += ro;    // has to be same as old r
                ans[inter[j].second.second] += inter[j].first - ro;  // take remaining
            }
            j++;
        }
    }

    ans[0] += l, ans[n-1] += r; // they can move boundless that way
    while (j < m) {
        ans[inter[j].second.first] += r;
        ans[inter[j].second.second] += l;
        j++;
    }

    for (int i=0; i<n; i++) cout << ans[i] << nl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 2 ms 492 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 2 ms 492 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 2 ms 492 KB Output is correct
20 Correct 32 ms 1388 KB Output is correct
21 Correct 31 ms 1516 KB Output is correct
22 Correct 37 ms 1516 KB Output is correct
23 Correct 27 ms 1644 KB Output is correct
24 Correct 38 ms 2660 KB Output is correct
25 Correct 109 ms 11088 KB Output is correct
26 Correct 104 ms 11088 KB Output is correct
27 Correct 99 ms 10832 KB Output is correct
28 Correct 111 ms 10796 KB Output is correct
29 Correct 116 ms 10724 KB Output is correct
30 Correct 102 ms 10316 KB Output is correct
31 Correct 96 ms 9940 KB Output is correct
32 Correct 82 ms 9808 KB Output is correct
33 Correct 12 ms 1892 KB Output is correct
34 Correct 107 ms 11088 KB Output is correct
35 Correct 101 ms 10820 KB Output is correct
36 Correct 102 ms 11088 KB Output is correct
37 Correct 104 ms 10960 KB Output is correct
38 Correct 107 ms 10916 KB Output is correct
39 Correct 106 ms 10924 KB Output is correct
40 Correct 109 ms 10832 KB Output is correct
41 Correct 32 ms 1516 KB Output is correct
42 Correct 93 ms 9936 KB Output is correct
43 Correct 98 ms 11112 KB Output is correct
44 Correct 34 ms 1664 KB Output is correct
45 Correct 102 ms 10960 KB Output is correct
46 Correct 107 ms 11216 KB Output is correct
47 Correct 106 ms 11216 KB Output is correct
48 Correct 106 ms 11176 KB Output is correct