Submission #153299

#TimeUsernameProblemLanguageResultExecution timeMemory
153299arnold518Holiday (IOI14_holiday)C++14
Compilation error
0 ms0 KiB
#include "holiday.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1e5; const int MAXS = 2e6; int N, S, D, A[MAXN+10]; vector<int> comp; int getcomp(int x) { return lower_bound(comp.begin(), comp.end(), x)-comp.begin(); } ll ans; struct Node { int cnt; ll sum; Node *lc, *rc; Node() : cnt(0), sum(0), lc(0), rc(0) {} }; Node nodes[MAXS+10]; int cnt=0; Node *tree[MAXN+10]; Node *newNode() { return &nodes[cnt++]; } void makeTree(Node *node, int tl, int tr) { if(tl==tr) return; int mid=tl+tr>>1; node->lc=newNode(); node->rc=newNode(); makeTree(node->lc, tl, mid); makeTree(node->rc, mid+1, tr); } Node *addTree(Node *node, int tl, int tr, int pos) { Node *ret=newNode(); if(pos<tl || tr<pos) return node; if(tl==tr) { ret->cnt=(node->cnt)+1; ret->sum=(node->sum)+comp[pos]; return ret; } int mid=tl+tr>>1; ret->lc=addTree(node->lc, tl, mid, pos); ret->rc=addTree(node->rc, mid+1, tr, pos); ret->cnt=(ret->lc->cnt)+(ret->rc->cnt); ret->sum=(ret->lc->sum)+(ret->rc->sum); return ret; } ll query(Node *nodel, Node *noder, int tl, int tr, int k) { if(tl==tr) return comp[tl]*min((ll)k, (noder->cnt)-(nodel->cnt)); int mid=tl+tr>>1; ll t=(noder->rc->cnt)-(nodel->rc->cnt); if(t>=k) return query(nodel->rc, noder->rc, mid+1, tr, k); else return query(nodel->lc, noder->lc, tl, mid, k-t)+(noder->rc->sum)-(nodel->rc->sum); } int dist(int l, int r) { return D-(r-l+min(abs(S-l), abs(r-S))); } void solve(int sl, int sr, int el, int er) { if(sl>sr) return; int i, j; int smid=sl+sr>>1, emid; ll val=-1; for(i=max(smid, el); i<=er; i++) { ll t=query(tree[smid-1], tree[i], 1, comp.size()-1, dist(smid, i)); if(t>val) val=t, emid=i; } ans=max(ans, val); solve(sl, smid-1, el, emid); solve(smid+1, sr, emid, er); } ll findMaxAttraction(int _N, int _S, int _D, int *_A) { int i, j; N=_N; S=_S; D=_D; S++; for(i=1; i<=N; i++) A[i]=_A[i-1], comp.push_back(A[i]); comp.push_back(-1); sort(comp.begin(), comp.end()); comp.erase(unique(comp.begin(), comp.end()), comp.end()); tree[0]=newNode(); makeTree(tree[0], 1, comp.size()-1); for(i=1; i<=N; i++) tree[i]=addTree(tree[i-1], 1, comp.size()-1, getcomp(A[i])); solve(1, N, 1, N); return ans; }

Compilation message (stderr)

holiday.cpp: In function 'void makeTree(Node*, int, int)':
holiday.cpp:34:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid=tl+tr>>1;
             ~~^~~
holiday.cpp: In function 'Node* addTree(Node*, int, int, int)':
holiday.cpp:51:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid=tl+tr>>1;
             ~~^~~
holiday.cpp: In function 'll query(Node*, Node*, int, int, int)':
holiday.cpp:61:68: error: no matching function for call to 'min(ll, int)'
     if(tl==tr) return comp[tl]*min((ll)k, (noder->cnt)-(nodel->cnt));
                                                                    ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from holiday.cpp:2:
/usr/include/c++/7/bits/stl_algobase.h:195:5: note: candidate: template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)
     min(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:195:5: note:   template argument deduction/substitution failed:
holiday.cpp:61:68: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
     if(tl==tr) return comp[tl]*min((ll)k, (noder->cnt)-(nodel->cnt));
                                                                    ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from holiday.cpp:2:
/usr/include/c++/7/bits/stl_algobase.h:243:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:243:5: note:   template argument deduction/substitution failed:
holiday.cpp:61:68: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
     if(tl==tr) return comp[tl]*min((ll)k, (noder->cnt)-(nodel->cnt));
                                                                    ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from holiday.cpp:2:
/usr/include/c++/7/bits/stl_algo.h:3450:5: note: candidate: template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)
     min(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3450:5: note:   template argument deduction/substitution failed:
holiday.cpp:61:68: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
     if(tl==tr) return comp[tl]*min((ll)k, (noder->cnt)-(nodel->cnt));
                                                                    ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from holiday.cpp:2:
/usr/include/c++/7/bits/stl_algo.h:3456:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)
     min(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
holiday.cpp:61:68: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
     if(tl==tr) return comp[tl]*min((ll)k, (noder->cnt)-(nodel->cnt));
                                                                    ^
holiday.cpp:62:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid=tl+tr>>1;
             ~~^~~
holiday.cpp: In function 'void solve(int, int, int, int)':
holiday.cpp:74:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int smid=sl+sr>>1, emid; ll val=-1;
              ~~^~~
holiday.cpp:73:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
holiday.cpp: In function 'll findMaxAttraction(int, int, int, int*)':
holiday.cpp:89:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for(i=1; i<=N; i++) A[i]=_A[i-1], comp.push_back(A[i]); comp.push_back(-1);
     ^~~
holiday.cpp:89:61: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
     for(i=1; i<=N; i++) A[i]=_A[i-1], comp.push_back(A[i]); comp.push_back(-1);
                                                             ^~~~
holiday.cpp:87:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^