답안 #762704

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
762704 2023-06-21T16:33:02 Z sheldon Snowball (JOI21_ho_t2) C++14
0 / 100
1 ms 340 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);
    }
    A = l, B = r;
    l = 0, r = 0;
    long long prev_l = 0, prev_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(l);
   ans[n - 1] += r;
   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:36: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]
   36 |     for (int i = 0; i < v.size(); ++i) {
      |                     ~~^~~~~~~~~~
Main.cpp:37: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]
   37 |         while (idx < deltas.size() && a[v[i][1]] + r < a[v[i][2]] + l) {
      |                ~~~~^~~~~~~~~~~~~~~
Main.cpp:20:15: warning: variable 'A' set but not used [-Wunused-but-set-variable]
   20 |     long long A, B;
      |               ^
Main.cpp:20:18: warning: variable 'B' set but not used [-Wunused-but-set-variable]
   20 |     long long A, B;
      |                  ^
Main.cpp:34:15: warning: unused variable 'prev_l' [-Wunused-variable]
   34 |     long long prev_l = 0, prev_r = 0;
      |               ^~~~~~
Main.cpp:34:27: warning: unused variable 'prev_r' [-Wunused-variable]
   34 |     long long prev_l = 0, prev_r = 0;
      |                           ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -