Submission #529538

# Submission time Handle Problem Language Result Execution time Memory
529538 2022-02-23T06:10:55 Z syl123456 Snowball (JOI21_ho_t2) C++17
100 / 100
811 ms 13004 KB
#include <bits/stdc++.h>
#define all(i) (i).begin(), (i).end()
using namespace std;
#define debug(args...) cout << '[' << #args << "] is [", DEBUG(false, args), cout << ']' << endl
template<typename T>
void DEBUG(bool _sp, T i) {
    if (_sp)
        cout << ' ';
    cout << i;
}
template<typename T, typename ...U>
void DEBUG(bool _sp, T i, U ...j) {
    if (_sp)
        cout << ' ';
    cout << i;
    DEBUG(true, j...);
}
template<typename T, typename U>
ostream& operator << (ostream &i, pair<T, U> j) {
    i << '(' << j.first << ", " << j.second << ')';
}
template<typename T>
ostream& operator << (ostream &i, vector<T> j) {
    i << '{' << j.size() << " :";
    for (T _i : j)
        i << ' ' << _i;
    i << '}';
}

typedef long long ll;
typedef pair<int, int> pi;
typedef double dd;

const int inf = 0x3f3f3f3f, lg = 20;
const ll mod = 1e9 + 7, INF = 0x3f3f3f3f3f3f3f3f;

typedef pair<ll, int> pl;

signed main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int n, q;
    cin >> n >> q;
    ll a[n], b[q];
    for (ll &i : a)
        cin >> i;
    for (ll &i : b)
        cin >> i;
    for (int i = 1; i < q; ++i)
        b[i] += b[i - 1];
    vector<pl> vl, vr;
    vl.emplace_back(0, 0), vr.emplace_back(0, 0);
    for (int i = 0; i < q; ++i) {
        if (b[i] < 0)
            vl.emplace_back(-b[i], i);
        else if (b[i] > 0)
            vr.emplace_back(b[i], i);
    }
    sort(all(vl)), sort(all(vr));
    vector<pl> tmp;
    for (auto [i, j] : vl) {
        while (!tmp.empty() && tmp.back().second >= j)
            tmp.pop_back();
        tmp.emplace_back(i, j);
    }
    vl = tmp, tmp.clear();
    for (auto [i, j] : vr) {
        while (!tmp.empty() && tmp.back().second >= j)
            tmp.pop_back();
        if (tmp.empty() || tmp.back().first < i)
            tmp.emplace_back(i, j);
    }
    vr = tmp;
    ll ans[n]{}, mxl = vl.back().first, mxr = vr.back().first;
    ans[0] += mxl, ans[n - 1] += mxr;
    for (int i = 0; i < n - 1; ++i) {
        if (a[i + 1] - a[i] >= mxl + mxr) {
            ans[i] += mxr, ans[i + 1] += mxl;
            continue;
        }
        ll len = a[i + 1] - a[i];
        ll l = max(0ll, len - mxl), r = min(len, mxr) + 1;
        while (l < r - 1) {
            ll mid = l + r >> 1;
            if (lower_bound(all(vr), pl(mid, -1))->second < lower_bound(all(vl), pl(len - mid + 1, -1))->second)
                l = mid;
            else
                r = mid;
        }
        ans[i] += l, ans[i + 1] += len - l;
    }
    for (ll i : ans)
        cout << i << '\n';
}

Compilation message

Main.cpp: In function 'std::ostream& operator<<(std::ostream&, std::pair<_T1, _T2>)':
Main.cpp:21:1: warning: no return statement in function returning non-void [-Wreturn-type]
   21 | }
      | ^
Main.cpp: In function 'std::ostream& operator<<(std::ostream&, std::vector<_Tp>)':
Main.cpp:28:1: warning: no return statement in function returning non-void [-Wreturn-type]
   28 | }
      | ^
Main.cpp: In function 'int main()':
Main.cpp:83:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   83 |             ll mid = l + r >> 1;
      |                      ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 280 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 5 ms 460 KB Output is correct
5 Correct 4 ms 460 KB Output is correct
6 Correct 4 ms 332 KB Output is correct
7 Correct 3 ms 332 KB Output is correct
8 Correct 4 ms 332 KB Output is correct
9 Correct 3 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 5 ms 460 KB Output is correct
16 Correct 5 ms 332 KB Output is correct
17 Correct 3 ms 460 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 280 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 5 ms 460 KB Output is correct
5 Correct 4 ms 460 KB Output is correct
6 Correct 4 ms 332 KB Output is correct
7 Correct 3 ms 332 KB Output is correct
8 Correct 4 ms 332 KB Output is correct
9 Correct 3 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 5 ms 460 KB Output is correct
16 Correct 5 ms 332 KB Output is correct
17 Correct 3 ms 460 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 32 ms 8084 KB Output is correct
21 Correct 37 ms 7996 KB Output is correct
22 Correct 31 ms 7988 KB Output is correct
23 Correct 40 ms 8032 KB Output is correct
24 Correct 109 ms 8164 KB Output is correct
25 Correct 808 ms 11340 KB Output is correct
26 Correct 811 ms 11380 KB Output is correct
27 Correct 790 ms 11112 KB Output is correct
28 Correct 739 ms 11124 KB Output is correct
29 Correct 651 ms 10988 KB Output is correct
30 Correct 303 ms 10716 KB Output is correct
31 Correct 66 ms 9528 KB Output is correct
32 Correct 48 ms 6244 KB Output is correct
33 Correct 56 ms 1464 KB Output is correct
34 Correct 479 ms 9892 KB Output is correct
35 Correct 507 ms 9808 KB Output is correct
36 Correct 784 ms 11284 KB Output is correct
37 Correct 726 ms 10820 KB Output is correct
38 Correct 729 ms 11164 KB Output is correct
39 Correct 733 ms 11352 KB Output is correct
40 Correct 382 ms 11236 KB Output is correct
41 Correct 36 ms 11072 KB Output is correct
42 Correct 46 ms 5344 KB Output is correct
43 Correct 320 ms 11372 KB Output is correct
44 Correct 35 ms 7972 KB Output is correct
45 Correct 65 ms 11196 KB Output is correct
46 Correct 253 ms 11568 KB Output is correct
47 Correct 198 ms 12640 KB Output is correct
48 Correct 102 ms 13004 KB Output is correct