Submission #762702

#TimeUsernameProblemLanguageResultExecution timeMemory
762702sheldonSnowball (JOI21_ho_t2)C++14
Compilation error
0 ms0 KiB
#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; 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); } 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; } } for (long long x : ans) { cout << x << ' '; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); solve(); }

Compilation message (stderr)

Main.cpp: In function 'void solve()':
Main.cpp:33: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]
   33 |     for (int i = 0; i < v.size(); ++i) {
      |                     ~~^~~~~~~~~~
Main.cpp:34: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]
   34 |         while (idx < deltas.size() && a[v[i][1]] + r < a[v[i]][2] + l) {
      |                ~~~~^~~~~~~~~~~~~~~
Main.cpp:34:57: error: no match for 'operator[]' (operand types are 'std::vector<long long int>' and '__gnu_cxx::__alloc_traits<std::allocator<std::array<long long int, 3> >, std::array<long long int, 3> >::value_type' {aka 'std::array<long long int, 3>'})
   34 |         while (idx < deltas.size() && a[v[i][1]] + r < a[v[i]][2] + l) {
      |                                                         ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 from Main.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1043:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = long long int; _Alloc = std::allocator<long long int>; std::vector<_Tp, _Alloc>::reference = long long int&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1043 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1043:28: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::array<long long int, 3> >, std::array<long long int, 3> >::value_type' {aka 'std::array<long long int, 3>'} to 'std::vector<long long int>::size_type' {aka 'long unsigned int'}
 1043 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1061:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) const [with _Tp = long long int; _Alloc = std::allocator<long long int>; std::vector<_Tp, _Alloc>::const_reference = const long long int&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1061:28: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::array<long long int, 3> >, std::array<long long int, 3> >::value_type' {aka 'std::array<long long int, 3>'} to 'std::vector<long long int>::size_type' {aka 'long unsigned int'}
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
Main.cpp:39:31: error: no match for 'operator[]' (operand types are 'std::vector<long long int>' and '__gnu_cxx::__alloc_traits<std::allocator<std::array<long long int, 3> >, std::array<long long int, 3> >::value_type' {aka 'std::array<long long int, 3>'})
   39 |         if (a[v[i][1]] + r > a[v[i]][2] + l) {
      |                               ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 from Main.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1043:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = long long int; _Alloc = std::allocator<long long int>; std::vector<_Tp, _Alloc>::reference = long long int&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1043 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1043:28: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::array<long long int, 3> >, std::array<long long int, 3> >::value_type' {aka 'std::array<long long int, 3>'} to 'std::vector<long long int>::size_type' {aka 'long unsigned int'}
 1043 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1061:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) const [with _Tp = long long int; _Alloc = std::allocator<long long int>; std::vector<_Tp, _Alloc>::const_reference = const long long int&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1061:28: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::array<long long int, 3> >, std::array<long long int, 3> >::value_type' {aka 'std::array<long long int, 3>'} to 'std::vector<long long int>::size_type' {aka 'long unsigned int'}
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
Main.cpp:31:15: warning: unused variable 'prev_l' [-Wunused-variable]
   31 |     long long prev_l = 0, prev_r = 0;
      |               ^~~~~~
Main.cpp:31:27: warning: unused variable 'prev_r' [-Wunused-variable]
   31 |     long long prev_l = 0, prev_r = 0;
      |                           ^~~~~~