Submission #811217

#TimeUsernameProblemLanguageResultExecution timeMemory
811217penguinmanDistributing Candies (IOI21_candies)C++17
Compilation error
0 ms0 KiB
#include "candies.h" #include <bits/stdc++.h> using std::cin; using std::cout; using std::vector; using std::string; using ll = int; using LL = long long; using vi = vector<ll>; using vii = vector<vi>; using pii = std::pair<ll,ll>; using std::endl; #define rep(i,j,k) for(ll i=ll(j); i<ll(k); i++) #define REP(i,j,k) for(ll i=ll(j); i<=ll(k); i++) #define per(i,j,k) for(ll i=ll(j); i>=ll(k); i--) #define ln "\n" #define pb emplace_back #define mp std::make_pair #define mtp std::make_tuple #define all(a) a.begin(),a.end() struct lazy_segment_tree{ ll N; ll log; vi max, min; vi lmax, lmin; vector<LL> sum, lsum; lazy_segment_tree(ll n){ N = 1; log = 0; while(N <= n){ N *= 2; log++; } sum.resize(2*N); max.resize(2*N); min.resize(2*N); lsum.resize(2*N); lmax.resize(2*N); lmin.resize(2*N); } void update(ll a, ll b, ll val){ ll l = a+N, r = b+N-1; per(i,log+1,0){ eval(l>>i); eval(r>>i); } while(l < r){ if(l & 1){ eval(l); if(val > 0) lmax[l] = val; else lmin[l] = val; lsum[l] += val; l++; } l >>= 1; if((r&1) == 0){ eval(r); if(val > 0) lmax[r] = val; else lmin[r] = val; lsum[r] += val; r--; } r >>= 1; } if(l == r){ eval(l); if(val > 0) lmax[l] = val; else lmin[l] = val; lsum[l] += val; } } /*void update(ll a, ll b, ll val, ll now = 1, ll l = 0, ll r = -1){ if(r == -1) r = N; if(r <= a || b <= l) return; eval(now); if(a <= l && r <= b){ if(val > 0) lmax[now] = val; else lmin[now] = val; lsum[now] += val; return; } update(a,b,val,now*2,l,(l+r)/2); update(a,b,val,now*2+1,(l+r)/2,r); }*/ pii calc(ll now){ now += N; per(i,log+1,0){ eval((now>>i)); } return mp(max[now], min[now]); } void eval(ll now){ if(lmax[now]){ max[now] = std::max(max[now], sum[now]+lmax[now]); if(now < N){ lmax[now*2] = std::max(lmax[now*2], lsum[now*2]+lmax[now]); lmax[now*2+1] = std::max(lmax[now*2+1], lsum[now*2+1]+lmax[now]); } lmax[now] = 0; } if(lmin[now]){ min[now] = std::min(min[now], sum[now]+lmin[now]); if(now < N){ lmin[now*2] = std::min(lmin[now*2], lsum[now*2]+lmin[now]); lmin[now*2+1] = std::min(lmin[now*2+1], lsum[now*2+1]+lmin[now]); } lmin[now] = 0; } if(lsum[now]){ sum[now] += lsum[now]; if(now < N){ lsum[now*2] += lsum[now]; lsum[now*2+1] += lsum[now]; } lsum[now] = 0; } lmax[now] = lmin[now] = lsum[now] = 0; } }; std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l, std::vector<int> r, std::vector<int> v) { int N = c.size(); ll Q = l.size(); vi left(N,-1), right(N,Q); while(true){ lazy_segment_tree seg(N); vi mid(N); bool flg = true; vii query(Q+1); rep(i,0,N){ if(left[i]+1 < right[i]){ mid[i] = (left[i]+right[i])/2; query[mid[i]].pb(i); flg = false; } } if(flg) break; per(i,Q,0){ if(i < Q){ seg.update(l[i], r[i]+1, v[i]); } for(auto el: query[i]){ auto ret = seg.calc(el); if(LL(c[el]) <= LL(ret.first)-LL(ret.second)) left[el] = mid[el]; else right[el] = mid[el]; } } } vector<int> ans(N); { vii max(Q+1), min(Q+1); rep(i,0,N){ if(left[i] == -1) max[0].pb(i); else{ if(v[left[i]] > 0){ min[left[i]].pb(i); } else{ max[left[i]].pb(i); } } } lazy_segment_tree seg(N); per(i,Q,0){ if(i < Q){ seg.update(l[i], r[i]+1, v[i]); } for(auto el: max[i]){ ans[el] = seg.calc(el).first; } for(auto el: min[i]){ ans[el] = c[el]+seg.calc(el).second; } } } return ans; }

Compilation message (stderr)

candies.cpp: In member function 'void lazy_segment_tree::eval(ll)':
candies.cpp:98:61: error: no matching function for call to 'max(__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type)'
   98 |             max[now] = std::max(max[now], sum[now]+lmax[now]);
      |                                                             ^
In file included from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.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:
candies.cpp:98:61: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
   98 |             max[now] = std::max(max[now], sum[now]+lmax[now]);
      |                                                             ^
In file included from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.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:
candies.cpp:98:61: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
   98 |             max[now] = std::max(max[now], sum[now]+lmax[now]);
      |                                                             ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from candies.cpp:3:
/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:
candies.cpp:98:61: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   98 |             max[now] = std::max(max[now], sum[now]+lmax[now]);
      |                                                             ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from candies.cpp:3:
/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:
candies.cpp:98:61: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   98 |             max[now] = std::max(max[now], sum[now]+lmax[now]);
      |                                                             ^
candies.cpp:100:74: error: no matching function for call to 'max(__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type)'
  100 |                 lmax[now*2] = std::max(lmax[now*2], lsum[now*2]+lmax[now]);
      |                                                                          ^
In file included from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.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:
candies.cpp:100:74: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
  100 |                 lmax[now*2] = std::max(lmax[now*2], lsum[now*2]+lmax[now]);
      |                                                                          ^
In file included from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.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:
candies.cpp:100:74: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
  100 |                 lmax[now*2] = std::max(lmax[now*2], lsum[now*2]+lmax[now]);
      |                                                                          ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from candies.cpp:3:
/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:
candies.cpp:100:74: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  100 |                 lmax[now*2] = std::max(lmax[now*2], lsum[now*2]+lmax[now]);
      |                                                                          ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from candies.cpp:3:
/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:
candies.cpp:100:74: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  100 |                 lmax[now*2] = std::max(lmax[now*2], lsum[now*2]+lmax[now]);
      |                                                                          ^
candies.cpp:101:80: error: no matching function for call to 'max(__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type)'
  101 |                 lmax[now*2+1] = std::max(lmax[now*2+1], lsum[now*2+1]+lmax[now]);
      |                                                                                ^
In file included from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.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:
candies.cpp:101:80: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
  101 |                 lmax[now*2+1] = std::max(lmax[now*2+1], lsum[now*2+1]+lmax[now]);
      |                                                                                ^
In file included from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.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:
candies.cpp:101:80: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
  101 |                 lmax[now*2+1] = std::max(lmax[now*2+1], lsum[now*2+1]+lmax[now]);
      |                                                                                ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from candies.cpp:3:
/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:
candies.cpp:101:80: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  101 |                 lmax[now*2+1] = std::max(lmax[now*2+1], lsum[now*2+1]+lmax[now]);
      |                                                                                ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from candies.cpp:3:
/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:
candies.cpp:101:80: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  101 |                 lmax[now*2+1] = std::max(lmax[now*2+1], lsum[now*2+1]+lmax[now]);
      |                                                                                ^
candies.cpp:106:61: error: no matching function for call to 'min(__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type)'
  106 |             min[now] = std::min(min[now], sum[now]+lmin[now]);
      |                                                             ^
In file included from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
candies.cpp:106:61: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
  106 |             min[now] = std::min(min[now], sum[now]+lmin[now]);
      |                                                             ^
In file included from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
candies.cpp:106:61: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
  106 |             min[now] = std::min(min[now], sum[now]+lmin[now]);
      |                                                             ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from candies.cpp:3:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
candies.cpp:106:61: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  106 |             min[now] = std::min(min[now], sum[now]+lmin[now]);
      |                                                             ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from candies.cpp:3:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
candies.cpp:106:61: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  106 |             min[now] = std::min(min[now], sum[now]+lmin[now]);
      |                                                             ^
candies.cpp:108:74: error: no matching function for call to 'min(__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type)'
  108 |                 lmin[now*2] = std::min(lmin[now*2], lsum[now*2]+lmin[now]);
      |                                                                          ^
In file included from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
candies.cpp:108:74: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
  108 |                 lmin[now*2] = std::min(lmin[now*2], lsum[now*2]+lmin[now]);
      |                                                                          ^
In file included from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
candies.cpp:108:74: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
  108 |                 lmin[now*2] = std::min(lmin[now*2], lsum[now*2]+lmin[now]);
      |                                                                          ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from candies.cpp:3:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
candies.cpp:108:74: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  108 |                 lmin[now*2] = std::min(lmin[now*2], lsum[now*2]+lmin[now]);
      |                                                                          ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from candies.cpp:3:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
candies.cpp:108:74: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  108 |                 lmin[now*2] = std::min(lmin[now*2], lsum[now*2]+lmin[now]);
      |                                                                          ^
candies.cpp:109:80: error: no matching function for call to 'min(__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type)'
  109 |                 lmin[now*2+1] = std::min(lmin[now*2+1], lsum[now*2+1]+lmin[now]);
      |                                                                                ^
In file included from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
candies.cpp:109:80: note:   deduced