Submission #886125

#TimeUsernameProblemLanguageResultExecution timeMemory
886125adaawfSum Zero (RMI20_sumzero)C++17
Compilation error
0 ms0 KiB
#include <iostream>
#include <map>
using namespace std;
long long int a[400005], c[400005];
int l[400005][19], f[100005];
map<long long int, long long int> m;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    m[0] = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        c[i] = c[i - 1] + a[i];
        f[i] = f[i - 1];
        if (m.count(c[i])) {
            f[i] = max(f[i], m[c[i]] + 1);
        }
        m[c[i]] = i;
    }
    for (int i = 1; i <= n; i++) {
        l[i][0] = f[i];
    }
    for (int i = 1; i <= 18; i++) {
        for (int j = 1; j <= n; j++) {
            if (l[j][i - 1] == 0) l[j][i] = 0;
            else l[j][i] = l[l[j][i - 1] - 1][i - 1];
        }
    }
    int q;
    cin >> q;
    for (int jj = 0; jj < q; jj++) {
        int x, y, res = 0;
        cin >> x >> y;
        for (int i = 18; i >= 0; i--) {
            if (y < x) break;
            if (l[y][i] >= x) {
                y = l[y][i] - 1;
                res += (1 << i);
            }
        }
        cout << res << '\n';
    }
}

Compilation message (stderr)

sumzero.cpp: In function 'int main()':
sumzero.cpp:18:41: error: no matching function for call to 'max(int&, std::map<long long int, long long int>::mapped_type)'
   18 |             f[i] = max(f[i], m[c[i]] + 1);
      |                                         ^
In file included 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 sumzero.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
sumzero.cpp:18:41: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::map<long long int, long long int>::mapped_type' {aka 'long long int'})
   18 |             f[i] = max(f[i], m[c[i]] + 1);
      |                                         ^
In file included 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 sumzero.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
sumzero.cpp:18:41: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::map<long long int, long long int>::mapped_type' {aka 'long long int'})
   18 |             f[i] = max(f[i], m[c[i]] + 1);
      |                                         ^