Submission #972571

#TimeUsernameProblemLanguageResultExecution timeMemory
972571VMaksimoski008Sum Zero (RMI20_sumzero)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; #define int long long const int LOG = 20; const int maxn = 2e5 + 5; int up[maxn][LOG]; int32_t main() { ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0); int n; cin >> n; vector<int> v(n+1), last(n+1, 1e9); for(int i=1; i<=n; i++) cin >> v[i]; map<ll, int> mp; mp[0] = 0; ll sum = 0; vector<pii> I; I.push_back({ 0, 0 }); for(int i=1; i<=n; i++) { sum += v[i]; if(mp.count(sum)) last[i] = mp[sum]; mp[sum] = i; if(last[i] != 1e9) I.push_back({ last[i], i }); } vector<int> pref; pref.push_back(0); for(int i=1; i<(int)I.size(); i++) { if((int)pref.size() == 0) pref.push_back(I[i].first); else pref.push_back(max(pref[i-1], I[i].first)); } for(int j=0; j<LOG; j++) for(int i=0; i<=n; i++) up[i][j] = -1; int p=0; for(int i=1; i<=n; i++) { while(p+1 < (int)I.size() && I[p+1].second <= i) p++; up[i][0] = pref[p]; } for(int j=1; j<LOG; j++) for(int i=1; i<=n; i++) if(up[i][j-1] != -1) up[i][j] = up[up[i][j-1]][j-1]; int q; cin >> q; while(q--) { int l, r, ans = 0; cin >> l >> r; l--; for(int j=LOG-1; j>=0; j--) { if(up[r][j] >= l && up[r][j] != -1) { ans += (1 << j); r = up[r][j]; } } cout << ans << '\n'; } return 0; }

Compilation message (stderr)

sumzero.cpp: In function 'int32_t main()':
sumzero.cpp:36:54: error: no matching function for call to 'max(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&, int&)'
   36 |         else pref.push_back(max(pref[i-1], I[i].first));
      |                                                      ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 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:36:54: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   36 |         else pref.push_back(max(pref[i-1], I[i].first));
      |                                                      ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 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:36:54: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   36 |         else pref.push_back(max(pref[i-1], I[i].first));
      |                                                      ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from sumzero.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
sumzero.cpp:36:54: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   36 |         else pref.push_back(max(pref[i-1], I[i].first));
      |                                                      ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from sumzero.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
sumzero.cpp:36:54: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   36 |         else pref.push_back(max(pref[i-1], I[i].first));
      |                                                      ^