제출 #299198

#제출 시각아이디문제언어결과실행 시간메모리
299198erd1휴가 (IOI14_holiday)C++14
컴파일 에러
0 ms0 KiB
#include"holiday.h" #include<bits/stdc++.h> using namespace std; #define ff first #define ss second #define all(x) (x).begin(), (x).end() #define pb push_back typedef int64_t lld; typedef pair<int, int> pii; struct node{ node *L = 0, *R = 0; int key; lld sum; int val, cnt = 1; node(int v) : key(rand()), sum(v), val(v) { } void up(){ sum = val, cnt = 1; if(L)sum += L->sum, cnt += L->cnt; if(R)sum += R->sum; } pair<node*, node*> splitVal(int s){ if(val < s){ if(!L)return{nullptr, this}; auto p = L->splitVal(s); L = p.ss; up(); return {p.ff, this}; }else{ if(!R)return{this, nullptr}; auto p = R->splitVal(s); R = p.ff; up(); return {this, p.ss}; } } pair<node*, node*> splitSize(int k){ if(k == (L?L->cnt:0)){ auto x = L; L = 0; up(); return {L, this}; } else if(k < (L?L->cnt:0)){ if(!L)return{nullptr, this}; auto p = L->splitSize(k); L = p.ss; up(); return {p.ff, this}; }else{ if(!R)return{this, nullptr}; auto p = R->splitSize(k-1-(L?L->cnt:0)); R = p.ff; up(); return {this, p.ss}; } } friend node* merge(node* a, node* b){ if(!a)return b; if(!b)return a; if(a->key < b->key) return a->R = merge(a->R, b), a->up(), a; else return b->L = merge(a, b->L), b->up(), b; } } *root = 0; long long int findMaxAttraction(int n, int start, int d, int attraction[]) { srand(time(0)); long long int ans = 0; for(int i = 0; i < min(n, d); i++){ if(!root)root = new node(attraction[i]); else{ auto p = root->splitVal(attraction[i]); root = merge(merge(p.ff, new node(attraction[i])), p.ss); } auto p = root->splitSize(d-i); //cout << d-i << " " << p.ff->sum << endl; ans = max(ans, p.ff->sum); root = merge(p.ff, p.ss); } return ans; }

컴파일 시 표준 에러 (stderr) 메시지

holiday.cpp: In member function 'std::pair<node*, node*> node::splitSize(int)':
holiday.cpp:34:12: warning: unused variable 'x' [-Wunused-variable]
   34 |       auto x = L; L = 0; up();
      |            ^
holiday.cpp: In function 'long long int findMaxAttraction(int, int, int, int*)':
holiday.cpp:70:31: error: no matching function for call to 'max(long long int&, lld&)'
   70 |       ans = max(ans, p.ff->sum);
      |                               ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from holiday.cpp:3:
/usr/include/c++/9/bits/stl_algobase.h:222:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  222 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:222:5: note:   template argument deduction/substitution failed:
holiday.cpp:70:31: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'lld' {aka 'long int'})
   70 |       ans = max(ans, p.ff->sum);
      |                               ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from holiday.cpp:3:
/usr/include/c++/9/bits/stl_algobase.h:268:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  268 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:268:5: note:   template argument deduction/substitution failed:
holiday.cpp:70:31: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'lld' {aka 'long int'})
   70 |       ans = max(ans, p.ff->sum);
      |                               ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from holiday.cpp:3:
/usr/include/c++/9/bits/stl_algo.h:3456:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3456 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
holiday.cpp:70:31: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   70 |       ans = max(ans, p.ff->sum);
      |                               ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from holiday.cpp:3:
/usr/include/c++/9/bits/stl_algo.h:3462:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3462 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
holiday.cpp:70:31: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   70 |       ans = max(ans, p.ff->sum);
      |                               ^