Submission #784616

# Submission time Handle Problem Language Result Execution time Memory
784616 2023-07-16T11:06:14 Z borisAngelov Snowball (JOI21_ho_t2) C++17
0 / 100
1 ms 340 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] = +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 = +inf;
    long long r = -inf;
    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 && ptr < intervals.size())
        {
            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] += 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:60:53: 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]
   60 |         while (r - l >= intervals[ptr].first && ptr < intervals.size())
      |                                                 ~~~~^~~~~~~~~~~~~~~~~~
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 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -