Submission #1050068

#TimeUsernameProblemLanguageResultExecution timeMemory
1050068matereElection (BOI18_election)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> using namespace std; int a[500005],pref[500005],suf[500005],lg[500005]; pair<int,int>spp[500005][20],sps[500005][20]; vector<int>v; int main(){ int n; char c; cin>>n; for(int i=2;i<=500004;i++) lg[i]=lg[i/2]+1; for(int i=1;i<=500004;i++) spp[i][0].first=sps[i][0].first=1e9; v.push_back(0); for(int i=1;i<=n;i++){ cin>>c; if(c=='T') v.push_back(i); a[i]=(c=='C')*2-1; pref[i]=pref[i-1]+a[i]; spp[i][0].first=pref[i]; spp[i][0].second=i; } v.push_back(n+1); for(int i=n;i>=1;i--){ suf[i]=suf[i+1]+a[i]; sps[i][0].first=suf[i]; sps[i][0].second=i; } for(int pr=1;pr<=19;pr++){ for(int i=1;i<=n;i++){ spp[i][pr].second=spp[i][pr-1].second; sps[i][pr].second=sps[i][pr-1].second; if(spp[i][pr-1].first>spp[min(n,i+(1<<(pr-1)))][pr-1].first) spp[i][pr].second=spp[min(n,i+(1<<(pr-1)))][pr-1].second; if(sps[i][pr-1].first>sps[min(n,i+(1<<(pr-1)))][pr-1].first) sps[i][pr].second=sps[min(n,i+(1<<(pr-1)))][pr-1].second; spp[i][pr].first=min(spp[i][pr-1].first,spp[min(n,i+(1<<(pr-1)))][pr-1].first); sps[i][pr].first=min(sps[i][pr-1].first,sps[min(n,i+(1<<(pr-1)))][pr-1].first); } } int q; cin>>q; for(int i=1;i<=q;i++){ int l,r; cin>>l>>r; int mn1=min(spp[l][lg[r-l+1]].first,spp[r-(1<<lg[r-l+1])+1][lg[r-l+1]].first); int mn1i=spp[l][lg[r-l+1]].second; if(spp[l][lg[r-l+1]].first>spp[r-(1<<lg[r-l+1])+1][lg[r-l+1]].first) mn1i=spp[r-(1<<lg[r-l+1])+1][lg[r-l+1]].second; int mn2=min(sps[l][lg[r-l+1]].first,sps[r-(1<<lg[r-l+1])+1][lg[r-l+1]].first); int mn2i=sps[l][lg[r-l+1]].second; if(sps[l][lg[r-l+1]].first>sps[r-(1<<lg[r-l+1])+1][lg[r-l+1]].first) mn2i=sps[r-(1<<lg[r-l+1])+1][lg[r-l+1]].second; mn1-=pref[l-1]; mn2-=suf[r+1]; cout<<max((long long)-mn1,max((long long)-mn2,-mn1-mn2-((upper_bound(v.begin(),v.end(),mn1i)-v.begin())-(lower_bound(v.begin(),v.end(),mn2i)-v.begin()))))<<endl; } }

Compilation message (stderr)

election.cpp: In function 'int main()':
election.cpp:50:161: error: no matching function for call to 'max(long long int, __gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type)'
   50 |         cout<<max((long long)-mn1,max((long long)-mn2,-mn1-mn2-((upper_bound(v.begin(),v.end(),mn1i)-v.begin())-(lower_bound(v.begin(),v.end(),mn2i)-v.begin()))))<<endl;
      |                                                                                                                                                                 ^
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/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from election.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:
election.cpp:50:161: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'})
   50 |         cout<<max((long long)-mn1,max((long long)-mn2,-mn1-mn2-((upper_bound(v.begin(),v.end(),mn1i)-v.begin())-(lower_bound(v.begin(),v.end(),mn2i)-v.begin()))))<<endl;
      |                                                                                                                                                                 ^
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/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from election.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:
election.cpp:50:161: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'})
   50 |         cout<<max((long long)-mn1,max((long long)-mn2,-mn1-mn2-((upper_bound(v.begin(),v.end(),mn1i)-v.begin())-(lower_bound(v.begin(),v.end(),mn2i)-v.begin()))))<<endl;
      |                                                                                                                                                                 ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from election.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:
election.cpp:50:161: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   50 |         cout<<max((long long)-mn1,max((long long)-mn2,-mn1-mn2-((upper_bound(v.begin(),v.end(),mn1i)-v.begin())-(lower_bound(v.begin(),v.end(),mn2i)-v.begin()))))<<endl;
      |                                                                                                                                                                 ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from election.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:
election.cpp:50:161: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   50 |         cout<<max((long long)-mn1,max((long long)-mn2,-mn1-mn2-((upper_bound(v.begin(),v.end(),mn1i)-v.begin())-(lower_bound(v.begin(),v.end(),mn2i)-v.begin()))))<<endl;
      |                                                                                                                                                                 ^