Submission #597206

#TimeUsernameProblemLanguageResultExecution timeMemory
597206DeepessonSum Zero (RMI20_sumzero)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #define MAX 405000 #define LOG 19 using ll = long long; int array[MAX]; int N; int jump[MAX][2]; int pulo_origem[MAX]; void simular_camada(int u){ for(int i=0;i!=N;++i)jump[i][0]=pulo_origem[i]; for(int j=1;j!=u+1;++j){ int cord = j&1; int oposto = !cord; for(int i=0;i!=N;++i){ int x = jump[i][oposto]; if(x<0)jump[i][cord]=x-1; else jump[i][cord]=jump[x][oposto]; } } } int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); std::cin>>N; for(int i=0;i!=N;++i)std::cin>>array[i]; std::map<ll,int> mapa; mapa[0]=-1; ll prev=-7; ll s=0; for(int i=0;i!=N;++i){ s+=array[i]; ll falta = s; if(mapa.find(falta)!=mapa.end()){ prev=std::max(prev,mapa[falta]); } pulo_origem[i]=prev; mapa[s]=i; } mapa.clear(); int Q; std::cin>>Q; int ans[Q]={},pos[Q],lim[Q]; for(int i=0;i!=Q;++i){ int l,r; std::cin>>l>>r;l-=2;--r; pos[i] = r; lim[i] = l; } ///Exponenciacao binaria for(int j=LOG-1;j!=-1;--j){ simular_camada(j); for(int i=0;i!=Q;++i){ if(pos[i]>=0&&jump[pos[i]][j&1]>=lim[i]){ ans[i]+=1<<j; pos[i]=jump[pos[i]][j&1]; } } } for(int i=0;i!=Q;++i)std::cout<<ans[i]<<"\n"; }

Compilation message (stderr)

sumzero.cpp: In function 'int main()':
sumzero.cpp:43:43: error: no matching function for call to 'max(ll&, std::map<long long int, int>::mapped_type&)'
   43 |             prev=std::max(prev,mapa[falta]);
      |                                           ^
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:43:43: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'std::map<long long int, int>::mapped_type' {aka 'int'})
   43 |             prev=std::max(prev,mapa[falta]);
      |                                           ^
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:43:43: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'std::map<long long int, int>::mapped_type' {aka 'int'})
   43 |             prev=std::max(prev,mapa[falta]);
      |                                           ^
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:43:43: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   43 |             prev=std::max(prev,mapa[falta]);
      |                                           ^
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:43:43: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   43 |             prev=std::max(prev,mapa[falta]);
      |                                           ^