Submission #784639

# Submission time Handle Problem Language Result Execution time Memory
784639 2023-07-16T11:22:38 Z borisAngelov Snowball (JOI21_ho_t2) C++17
100 / 100
85 ms 13872 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 200005;
const long long inf = 1e18;

int n, q;

long long a[maxn];

vector<pair<long long, int>> intervals;

long long ans[maxn];

void fastIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    fastIO();

    cin >> n >> q;

    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
    }

    a[0] = -inf;
    a[n + 1] = +inf;

    for (int i = 1; i <= n + 1; ++i)
    {
        intervals.push_back(make_pair(a[i] - a[i - 1], i - 1));
    }

    sort(intervals.begin(), intervals.end());

    long long l = 0;
    long long r = 0;
    long long sum = 0;

    int ptr = 0;

    for (int i = 1; i <= q; ++i)
    {
        long long power;
        cin >> power;

        sum += power;

        l = min(l, sum);
        r = max(r, sum);

        while (r - l >= intervals[ptr].first)
        {
            if (power > 0)
            {
                ans[intervals[ptr].second] += intervals[ptr].first + l;
                ans[intervals[ptr].second + 1] -= l;
            }
            else
            {
                ans[intervals[ptr].second] += r;
                ans[intervals[ptr].second + 1] += intervals[ptr].first - r;
            }

            ++ptr;
        }
    }

    while (ptr < intervals.size())
    {
        ans[intervals[ptr].second] += r;
        ans[intervals[ptr].second + 1] -= l;
        ++ptr;
    }

    for (int i = 1; i <= n; ++i)
    {
        cout << ans[i] << "\n";
    }

    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:77:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |     while (ptr < intervals.size())
      |            ~~~~^~~~~~~~~~~~~~~~~~
# 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 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 380 KB Output is correct
9 Correct 1 ms 356 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 276 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 336 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 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 380 KB Output is correct
9 Correct 1 ms 356 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 276 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 18 ms 2372 KB Output is correct
21 Correct 20 ms 2232 KB Output is correct
22 Correct 24 ms 2004 KB Output is correct
23 Correct 16 ms 2004 KB Output is correct
24 Correct 19 ms 2816 KB Output is correct
25 Correct 63 ms 12004 KB Output is correct
26 Correct 63 ms 11920 KB Output is correct
27 Correct 63 ms 11608 KB Output is correct
28 Correct 66 ms 11776 KB Output is correct
29 Correct 67 ms 11188 KB Output is correct
30 Correct 62 ms 10656 KB Output is correct
31 Correct 56 ms 10072 KB Output is correct
32 Correct 46 ms 10224 KB Output is correct
33 Correct 7 ms 1620 KB Output is correct
34 Correct 64 ms 12320 KB Output is correct
35 Correct 63 ms 11732 KB Output is correct
36 Correct 63 ms 11988 KB Output is correct
37 Correct 70 ms 11676 KB Output is correct
38 Correct 78 ms 11612 KB Output is correct
39 Correct 67 ms 11728 KB Output is correct
40 Correct 62 ms 11712 KB Output is correct
41 Correct 20 ms 3016 KB Output is correct
42 Correct 55 ms 10140 KB Output is correct
43 Correct 85 ms 13492 KB Output is correct
44 Correct 19 ms 2892 KB Output is correct
45 Correct 59 ms 11768 KB Output is correct
46 Correct 59 ms 13564 KB Output is correct
47 Correct 73 ms 13792 KB Output is correct
48 Correct 59 ms 13872 KB Output is correct