Submission #772741

# Submission time Handle Problem Language Result Execution time Memory
772741 2023-07-04T10:52:08 Z BlockOG Fountain (eJOI20_fountain) C++14
Compilation error
0 ms 0 KB
#include <iostream>
#include <vector>
#include <utility>
#include <climits>

using namespace std;

int diameters[100000];
int next[100000][20];
int sum[100000][20];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, q; cin >> n >> q;

    for (int i = 0; i < n; i++) cin >> diameters[i] >> sum[i][0];

    vector<pair<int, int>> st = { { INT_MAX, -1 } };
    for (int i = n - 1; i >= 0; i--) {
        while (st.back().first <= diameters[i]) st.pop_back();
        next[i][0] = st.back().second;
        st.push_back({ diameters[i], i });
    }

    for (int j = 1; j < 20; j++) {
        for (int i = 0; i < n; i++) {
            if (next[i][j - 1] == -1) {
                next[i][j] = -1;
                sum[i][j] = sum[i][j - 1];
                continue;
            }
            next[i][j] = next[next[i][j - 1]][j - 1];
            sum[i][j] = sum[i][j - 1] + sum[next[i][j - 1]][j - 1];
        }
    }

    for (int it = 0; it < q; it++) {
        int r, v; cin >> r >> v; r--;

        for (int i = 19; i >= 0; i--) {
            if (sum[r][i] >= v) continue;
            v -= sum[r][i];
            r = next[r][i];
            if (r == -1) break;
        }

        cout << r + 1 << endl;
    }
}

Compilation message

fountain.cpp: In function 'int main()':
fountain.cpp:24:9: error: reference to 'next' is ambiguous
   24 |         next[i][0] = st.back().second;
      |         ^~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:66,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from fountain.cpp:1:
/usr/include/c++/10/bits/stl_iterator_base_funcs.h:213:5: note: candidates are: 'template<class _InputIterator> _InputIterator std::next(_InputIterator, typename std::iterator_traits<_Iter>::difference_type)'
  213 |     next(_InputIterator __x, typename
      |     ^~~~
fountain.cpp:9:5: note:                 'int next [100000][20]'
    9 | int next[100000][20];
      |     ^~~~
fountain.cpp:30:17: error: reference to 'next' is ambiguous
   30 |             if (next[i][j - 1] == -1) {
      |                 ^~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:66,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from fountain.cpp:1:
/usr/include/c++/10/bits/stl_iterator_base_funcs.h:213:5: note: candidates are: 'template<class _InputIterator> _InputIterator std::next(_InputIterator, typename std::iterator_traits<_Iter>::difference_type)'
  213 |     next(_InputIterator __x, typename
      |     ^~~~
fountain.cpp:9:5: note:                 'int next [100000][20]'
    9 | int next[100000][20];
      |     ^~~~
fountain.cpp:31:17: error: reference to 'next' is ambiguous
   31 |                 next[i][j] = -1;
      |                 ^~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:66,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from fountain.cpp:1:
/usr/include/c++/10/bits/stl_iterator_base_funcs.h:213:5: note: candidates are: 'template<class _InputIterator> _InputIterator std::next(_InputIterator, typename std::iterator_traits<_Iter>::difference_type)'
  213 |     next(_InputIterator __x, typename
      |     ^~~~
fountain.cpp:9:5: note:                 'int next [100000][20]'
    9 | int next[100000][20];
      |     ^~~~
fountain.cpp:35:13: error: reference to 'next' is ambiguous
   35 |             next[i][j] = next[next[i][j - 1]][j - 1];
      |             ^~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:66,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from fountain.cpp:1:
/usr/include/c++/10/bits/stl_iterator_base_funcs.h:213:5: note: candidates are: 'template<class _InputIterator> _InputIterator std::next(_InputIterator, typename std::iterator_traits<_Iter>::difference_type)'
  213 |     next(_InputIterator __x, typename
      |     ^~~~
fountain.cpp:9:5: note:                 'int next [100000][20]'
    9 | int next[100000][20];
      |     ^~~~
fountain.cpp:35:26: error: reference to 'next' is ambiguous
   35 |             next[i][j] = next[next[i][j - 1]][j - 1];
      |                          ^~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:66,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from fountain.cpp:1:
/usr/include/c++/10/bits/stl_iterator_base_funcs.h:213:5: note: candidates are: 'template<class _InputIterator> _InputIterator std::next(_InputIterator, typename std::iterator_traits<_Iter>::difference_type)'
  213 |     next(_InputIterator __x, typename
      |     ^~~~
fountain.cpp:9:5: note:                 'int next [100000][20]'
    9 | int next[100000][20];
      |     ^~~~
fountain.cpp:35:31: error: reference to 'next' is ambiguous
   35 |             next[i][j] = next[next[i][j - 1]][j - 1];
      |                               ^~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:66,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from fountain.cpp:1:
/usr/include/c++/10/bits/stl_iterator_base_funcs.h:213:5: note: candidates are: 'template<class _InputIterator> _InputIterator std::next(_InputIterator, typename std::iterator_traits<_Iter>::difference_type)'
  213 |     next(_InputIterator __x, typename
      |     ^~~~
fountain.cpp:9:5: note:                 'int next [100000][20]'
    9 | int next[100000][20];
      |     ^~~~
fountain.cpp:36:45: error: reference to 'next' is ambiguous
   36 |             sum[i][j] = sum[i][j - 1] + sum[next[i][j - 1]][j - 1];
      |                                             ^~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:66,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from fountain.cpp:1:
/usr/include/c++/10/bits/stl_iterator_base_funcs.h:213:5: note: candidates are: 'template<class _InputIterator> _InputIterator std::next(_InputIterator, typename std::iterator_traits<_Iter>::difference_type)'
  213 |     next(_InputIterator __x, typename
      |     ^~~~
fountain.cpp:9:5: note:                 'int next [100000][20]'
    9 | int next[100000][20];
      |     ^~~~
fountain.cpp:46:17: error: reference to 'next' is ambiguous
   46 |             r = next[r][i];
      |                 ^~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:66,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from fountain.cpp:1:
/usr/include/c++/10/bits/stl_iterator_base_funcs.h:213:5: note: candidates are: 'template<class _InputIterator> _InputIterator std::next(_InputIterator, typename std::iterator_traits<_Iter>::difference_type)'
  213 |     next(_InputIterator __x, typename
      |     ^~~~
fountain.cpp:9:5: note:                 'int next [100000][20]'
    9 | int next[100000][20];
      |     ^~~~