Submission #601513

# Submission time Handle Problem Language Result Execution time Memory
601513 2022-07-22T06:34:19 Z pakhomovee Snowball (JOI21_ho_t2) C++17
100 / 100
99 ms 13752 KB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define int long long

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, q;
    cin >> n >> q;
    vector<int> x(n);
    for (int& i : x) {
        cin >> i;
    }
    vector<pair<int, int>> t;
    for (int i = 0; i + 1 < n; ++i) {
        t.push_back({x[i + 1] - x[i], i});
    }
    sort(t.begin(), t.end());
    int minDelta = 0, maxDelta = 0;
    int currDelta = 0;
    int ptr = 0;
    vector<int> res(n, 0);
    for (int i = 0; i < q; ++i) {
        int w;
        cin >> w;
        int prevMaxDelta = maxDelta;
        int prevMinDelta = minDelta;
        currDelta += w;
        minDelta = min(minDelta, currDelta);
        maxDelta = max(maxDelta, currDelta);
        while (ptr < t.size() && t[ptr].first <= maxDelta - minDelta) {
            if (prevMaxDelta == maxDelta) {
                res[t[ptr].second] += maxDelta;
                res[t[ptr].second + 1] += t[ptr].first - maxDelta;
            } else {
                res[t[ptr].second] += t[ptr].first - abs(minDelta);
                res[t[ptr].second + 1] += abs(minDelta);
            }
            ++ptr;
        }
    }
    for (int i = ptr; i < t.size(); ++i) {
        res[t[i].second] += maxDelta;
        res[t[i].second + 1] += abs(minDelta);
    }
    res[0] += abs(minDelta);
    res.back() += maxDelta;
    for (int i : res) {
        cout << i << ' ';
    }
}

Compilation message

Main.cpp: In function 'int32_t main()':
Main.cpp:36:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         while (ptr < t.size() && t[ptr].first <= maxDelta - minDelta) {
      |                ~~~~^~~~~~~~~~
Main.cpp:32:13: warning: unused variable 'prevMinDelta' [-Wunused-variable]
   32 |         int prevMinDelta = minDelta;
      |             ^~~~~~~~~~~~
Main.cpp:47:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for (int i = ptr; i < t.size(); ++i) {
      |                       ~~^~~~~~~~~~
# 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 2 ms 468 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 4 ms 432 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 2 ms 380 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 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 2 ms 468 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 4 ms 432 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 2 ms 380 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 24 ms 2352 KB Output is correct
21 Correct 59 ms 2216 KB Output is correct
22 Correct 25 ms 1968 KB Output is correct
23 Correct 22 ms 1852 KB Output is correct
24 Correct 26 ms 2720 KB Output is correct
25 Correct 85 ms 11816 KB Output is correct
26 Correct 90 ms 11792 KB Output is correct
27 Correct 84 ms 11456 KB Output is correct
28 Correct 86 ms 11576 KB Output is correct
29 Correct 98 ms 11160 KB Output is correct
30 Correct 80 ms 10512 KB Output is correct
31 Correct 78 ms 9864 KB Output is correct
32 Correct 63 ms 10036 KB Output is correct
33 Correct 9 ms 1512 KB Output is correct
34 Correct 82 ms 12204 KB Output is correct
35 Correct 88 ms 11668 KB Output is correct
36 Correct 85 ms 11836 KB Output is correct
37 Correct 82 ms 11548 KB Output is correct
38 Correct 81 ms 11408 KB Output is correct
39 Correct 79 ms 11668 KB Output is correct
40 Correct 83 ms 11592 KB Output is correct
41 Correct 29 ms 2968 KB Output is correct
42 Correct 75 ms 10008 KB Output is correct
43 Correct 85 ms 13348 KB Output is correct
44 Correct 43 ms 2856 KB Output is correct
45 Correct 84 ms 11584 KB Output is correct
46 Correct 99 ms 13508 KB Output is correct
47 Correct 83 ms 13752 KB Output is correct
48 Correct 86 ms 13740 KB Output is correct