Submission #763795

# Submission time Handle Problem Language Result Execution time Memory
763795 2023-06-22T21:28:33 Z sheldon Snowball (JOI21_ho_t2) C++14
100 / 100
77 ms 18916 KB
#include <bits/stdc++.h>

using namespace std;
#define int long long

void solve() {
    int n, q;
    cin >> n >> q;
    vector<long long> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<array<long long, 3>> v;
    vector<int> ans(n);
    for (int i = 0; i + 1 < n; ++i) {
        v.push_back({abs(a[i] - a[i + 1]), 1LL * i, 1LL * i + 1});
    }
    sort(v.begin(), v.end());
    long long l = 0, r = 0, delta = 0;
    long long A, B;
    vector<long long> deltas;
    for (int i = 0; i < q; ++i) {
        long long x;
        cin >> x;
        delta += x;
        if (delta < l || delta > r) {
            deltas.push_back(delta);
        }
        l = min(delta, l);
        r = max(delta, r);
    }
    if (n == 1) {
        cout << l + r << '\n';
        return;
    }
    A = l, B = r;
    l = 0, r = 0;
    int idx = 0;
    for (int i = 0; i < v.size(); ++i) {
        while (idx < deltas.size() && a[v[i][1]] + r < a[v[i][2]] + l) {
            l = min(l, deltas[idx]);
            r = max(r, deltas[idx]);
            ++idx;
        }
        if (a[v[i][1]] + r > a[v[i][2]] + l) {
            if (deltas[idx - 1] < 0) {
                ans[v[i][1]] += r;
                ans[v[i][2]] += v[i][0] - r;
            } else {
                ans[v[i][2]] += abs(l);
                ans[v[i][1]] += v[i][0] - abs(l);
            }
        }  else {
            ans[v[i][2]] += abs(l);
            ans[v[i][1]] += r;
        }
   }
   ans[0] += abs(A);
   ans[n - 1] += B;
   for (long long x : ans) {
        cout << x << '\n';
   }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:39:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for (int i = 0; i < v.size(); ++i) {
      |                     ~~^~~~~~~~~~
Main.cpp:40:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         while (idx < deltas.size() && a[v[i][1]] + r < a[v[i][2]] + l) {
      |                ~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory 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 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 456 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 2 ms 464 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 456 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory 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 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 456 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 2 ms 464 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 456 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 26 ms 4164 KB Output is correct
21 Correct 19 ms 3984 KB Output is correct
22 Correct 20 ms 3920 KB Output is correct
23 Correct 20 ms 3772 KB Output is correct
24 Correct 21 ms 5064 KB Output is correct
25 Correct 72 ms 17092 KB Output is correct
26 Correct 76 ms 17068 KB Output is correct
27 Correct 70 ms 16428 KB Output is correct
28 Correct 71 ms 16552 KB Output is correct
29 Correct 69 ms 14384 KB Output is correct
30 Correct 67 ms 12484 KB Output is correct
31 Correct 66 ms 12484 KB Output is correct
32 Correct 65 ms 12608 KB Output is correct
33 Correct 8 ms 1872 KB Output is correct
34 Correct 69 ms 13876 KB Output is correct
35 Correct 68 ms 13620 KB Output is correct
36 Correct 77 ms 16972 KB Output is correct
37 Correct 73 ms 16328 KB Output is correct
38 Correct 74 ms 16424 KB Output is correct
39 Correct 71 ms 16680 KB Output is correct
40 Correct 74 ms 16712 KB Output is correct
41 Correct 20 ms 4668 KB Output is correct
42 Correct 61 ms 12592 KB Output is correct
43 Correct 60 ms 18572 KB Output is correct
44 Correct 20 ms 4556 KB Output is correct
45 Correct 68 ms 16692 KB Output is correct
46 Correct 66 ms 18732 KB Output is correct
47 Correct 70 ms 16848 KB Output is correct
48 Correct 68 ms 18916 KB Output is correct