# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
443514 | 2021-07-10T16:30:46 Z | mjhmjh1104 | Distributing Candies (IOI21_candies) | C++17 | Compilation error |
0 ms | 0 KB |
#include "candies.h" #include <vector> #include <algorithm> using namespace std; struct Move { long long o; long long n; long long c; }; vector<Move> V; long long cnt; vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) { cnt = 0; V.clear(); int n = (int)c.size(), q = (int)v.size(); long long globalMin = 0, globalMax = 0; vector<int> s(n); for (int t = 0; t < q; t++) { long long tmp_curr = v[t]; if (tmp_curr > 0) { long long curr = tmp_curr; while (!V.empty()) { if (V.back().n > V.back().o) { if (V.back().o < cnt) { tmp_curr = cnt + tmp_curr - V.back().o; cnt = V.back().o; } V.pop_back(); } else if (V.back().c <= curr) V.pop_back(); else break; } } else { long long curr = -tmp_curr; while (!V.empty()) { if (V.back().n < V.back().o) { if (V.back().o > cnt) { tmp_curr = cnt + tmp_curr - V.back().o; cnt = V.back().o; } V.pop_back(); } else if (V.back().c <= curr) V.pop_back(); else break; } } V.push_back(Move{ cnt, cnt + tmp_curr, tmp_curr > 0 ? tmp_curr : -tmp_curr }); cnt += tmp_curr; globalMin = min(globalMin, cnt), globalMax = max(globalMax, cnt); } //for (auto &i: V) printf("%lld %lld %d\n", i.o, i.n, i.c); reverse(V.begin(), V.end()); for (int i = 0; i < n; i++) { long long l = min(v.back().o, v.back().n), r = max(v.back().o, v.back().n); if (V.back().c > c[i]) { Move x = *lower_bound(V.begin(), V.end(), Move{ 0LL, 0LL, c[i] }, [](const Move &a, const Move &b) { return a.c < b.c; }); if (x.o > x.n) l = x.n, r = l + c[i]; else r = x.n, l = r - c[i]; //printf("%lld %lld %d\n", x.o, x.n, x.c); } //printf("! %lld %lld\n", l, r); if (l < 0) s[i] = cnt - l; else if (r > c[i]) s[i] = cnt - r + c[i]; else s[i] = cnt; } return s; }
Compilation message
candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)': candies.cpp:54:36: error: request for member 'o' in 'v.std::vector<int>::back()', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} 54 | long long l = min(v.back().o, v.back().n), r = max(v.back().o, v.back().n); | ^ candies.cpp:54:48: error: request for member 'n' in 'v.std::vector<int>::back()', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} 54 | long long l = min(v.back().o, v.back().n), r = max(v.back().o, v.back().n); | ^ candies.cpp:59:48: error: no match for 'operator=' (operand types are 'std::vector<int>' and 'long long int') 59 | if (x.o > x.n) l = x.n, r = l + c[i]; | ^ In file included from /usr/include/c++/10/vector:72, from candies.h:1, from candies.cpp:1: /usr/include/c++/10/bits/vector.tcc:198:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]' 198 | vector<_Tp, _Alloc>:: | ^~~~~~~~~~~~~~~~~~~ /usr/include/c++/10/bits/vector.tcc:199:42: note: no known conversion for argument 1 from 'long long int' to 'const std::vector<int>&' 199 | operator=(const vector<_Tp, _Alloc>& __x) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~ In file included from /usr/include/c++/10/vector:67, from candies.h:1, from candies.cpp:1: /usr/include/c++/10/bits/stl_vector.h:709:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = int; _Alloc = std::allocator<int>]' 709 | operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move()) | ^~~~~~~~ /usr/include/c++/10/bits/stl_vector.h:709:26: note: no known conversion for argument 1 from 'long long int' to 'std::vector<int>&&' 709 | operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move()) | ~~~~~~~~~^~~ /usr/include/c++/10/bits/stl_vector.h:730:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>]' 730 | operator=(initializer_list<value_type> __l) | ^~~~~~~~ /usr/include/c++/10/bits/stl_vector.h:730:46: note: no known conversion for argument 1 from 'long long int' to 'std::initializer_list<int>' 730 | operator=(initializer_list<value_type> __l) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~ candies.cpp:60:24: error: no match for 'operator=' (operand types are 'std::vector<int>' and 'long long int') 60 | else r = x.n, l = r - c[i]; | ^ In file included from /usr/include/c++/10/vector:72, from candies.h:1, from candies.cpp:1: /usr/include/c++/10/bits/vector.tcc:198:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]' 198 | vector<_Tp, _Alloc>:: | ^~~~~~~~~~~~~~~~~~~ /usr/include/c++/10/bits/vector.tcc:199:42: note: no known conversion for argument 1 from 'long long int' to 'const std::vector<int>&' 199 | operator=(const vector<_Tp, _Alloc>& __x) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~ In file included from /usr/include/c++/10/vector:67, from candies.h:1, from candies.cpp:1: /usr/include/c++/10/bits/stl_vector.h:709:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = int; _Alloc = std::allocator<int>]' 709 | operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move()) | ^~~~~~~~ /usr/include/c++/10/bits/stl_vector.h:709:26: note: no known conversion for argument 1 from 'long long int' to 'std::vector<int>&&' 709 | operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move()) | ~~~~~~~~~^~~ /usr/include/c++/10/bits/stl_vector.h:730:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>]' 730 | operator=(initializer_list<value_type> __l) | ^~~~~~~~ /usr/include/c++/10/bits/stl_vector.h:730:46: note: no known conversion for argument 1 from 'long long int' to 'std::initializer_list<int>' 730 | operator=(initializer_list<value_type> __l) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~ candies.cpp:60:33: error: no match for 'operator-' (operand types are 'std::vector<int>' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}) 60 | else r = x.n, l = r - c[i]; In file included from /usr/include/c++/10/bits/stl_algobase.h:67, from /usr/include/c++/10/vector:60, from candies.h:1, from candies.cpp:1: /usr/include/c++/10/bits/stl_iterator.h:500:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__y.base() - __x.base())) std::operator-(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)' 500 | operator-(const reverse_iterator<_IteratorL>& __x, | ^~~~~~~~ /usr/include/c++/10/bits/stl_iterator.h:500:5: note: template argument deduction/substitution failed: candies.cpp:60:38: note: 'std::vector<int>' is not derived from 'const std::reverse_iterator<_Iterator>' 60 | else r = x.n, l = r - c[i]; | ^ In file included from /usr/include/c++/10/bits/stl_algobase.h:67, from /usr/include/c++/10/vector:60, from candies.h:1, from candies.cpp:1: /usr/include/c++/10/bits/stl_iterator.h:1533:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__x.base() - __y.base())) std::operator-(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorR>&)' 1533 | operator-(const move_iterator<_IteratorL>& __x, | ^~~~~~~~ /usr/include/c++/10/bits/stl_iterator.h:1533:5: note: template argument deduction/substitution failed: candies.cpp:60:38: note: 'std::vector<int>' is not derived from 'const std::move_iterator<_IteratorL>' 60 | else r = x.n, l = r - c[i]; | ^ In file included from /usr/include/c++/10/bits/stl_algobase.h:67, from /usr/include/c++/10/vector:60, from candies.h:1, from candies.cpp:1: /usr/include/c++/10/bits/stl_iterator.h:1164:5: note: candidate: 'template<class _IteratorL, class _IteratorR, class _Container> decltype ((__lhs.base() - __rhs.base())) __gnu_cxx::operator-(const __gnu_cxx::__normal_iterator<_IteratorL, _Container>&, const __gnu_cxx::__normal_iterator<_IteratorR, _Container>&)' 1164 | operator-(const __normal_iterator<_IteratorL, _Container>& __lhs, | ^~~~~~~~ /usr/include/c++/10/bits/stl_iterator.h:1164:5: note: template argument deduction/substitution failed: candies.cpp:60:38: note: 'std::vector<int>' is not derived from 'const __gnu_cxx::__normal_iterator<_IteratorL, _Container>' 60 | else r = x.n, l = r - c[i]; | ^ In file included from /usr/include/c++/10/bits/stl_algobase.h:67, from /usr/include/c++/10/vector:60, from candies.h:1, from candies.cpp:1: /usr/include/c++/10/bits/stl_iterator.h:1177:5: note: candidate: 'template<class _Iterator, class _Container> typename __gnu_cxx::__normal_iterator<_Iterator, _Container>::difference_type __gnu_cxx::operator-(const __gnu_cxx::__normal_iterator<_Iterator, _Container>&, const __gnu_cxx::__normal_iterator<_Iterator, _Container>&)' 1177 | operator-(const __normal_iterator<_Iterator, _Container>& __lhs, | ^~~~~~~~ /usr/include/c++/10/bits/stl_iterator.h:1177:5: note: template argument deduction/substitution failed: candies.cpp:60:38: note: 'std::vector<int>' is not derived from 'const __gnu_cxx::__normal_iterator<_Iterator, _Container>' 60 | else r = x.n, l = r - c[i]; | ^ candies.cpp:65:20: error: no match for 'operator>' (operand types are 'std::vector<int>' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}) 65 | else if (r > c[i]) s[i] = cnt - r + c[i]; In file included from /usr/include/c++/10/bits/stl_algobase.h:64, from /usr/include/c++/10/vector:60, from candies.h:1, from candies.cpp:1: /usr/include/c++/10/bits/stl_pair.h:502:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator>(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)' 502 | operator>(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) | ^~~~~~~~ /usr/include/c++/10/bits/stl_pair.h:502:5: note: template argument deduction/substitution failed: candies.cpp:65:25: note: 'std::vector<int>' is not derived from 'const std::pair<_T1, _T2>' 65 | else if (r > c[i]) s[i] = cnt - r + c[i]; | ^ In file included from /usr/include/c++/10/bits/stl_algobase.h:67, from /usr/include/c++/10/vector:60, from candies.h:1, from candies.cpp:1: /usr/include/c++/10/bits/stl_iterator.h:378:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator>(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)' 378 | operator>(const reverse_iterator<_Iterator>& __x, | ^~~~~~~~ /usr/include/c++/10/bits/stl_iterator.h:378:5: note: template argument deduction/substitution failed: candies.cpp:65:25: note: 'std::vector<int>' is not derived from 'const std::reverse_iterator<_Iterator>' 65 | else if (r > c[i]) s[i] = cnt - r + c[i]; | ^ In file included from /usr/include/c++/10/bits/stl_algobase.h:67, from /usr/include/c++/10/vector:60, from candies.h:1, from candies.cpp:1: /usr/include/c++/10/bits/stl_iterator.h:416:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator>(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)' 416 | operator>(const reverse_iterator<_IteratorL>& __x, | ^~~~~~~~ /usr/include/c++/10/bits/stl_iterator.h:416:5: note: template argument deduction/substitution failed: candies.cpp:65:25: note: 'std::vector<int>' is not derived from 'const std::reverse_iterator<_Iterator>' 65 | else if (r > c[i]) s[i] = cnt - r + c[i]; | ^ In file included from /usr/include/c++/10/bits/stl_algobase.h:67, from /usr/include/c++/10/vector:60, from candies.h:1, from candies.cpp:1: /usr/include/c++/10/bits/stl_iterator.h:1469:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator>(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorR>&)' 1469 | operator>(const move_iterator<_IteratorL>& __x, | ^~~~~~~~ /usr/include/c++/10/bits/stl_iterator.h:1469:5: note: template argument deduction/substitution failed: candies.cpp:65:25: note: 'std::vector<int>' is not derived from 'const std::move_iterator<_IteratorL>' 65 | else if (r > c[i]) s[i] = cnt - r + c[i]; | ^ In file included from /usr/include/c++/10/bits/stl_algobase.h:67, from /usr/include/c++/10/vector:60, from candies.h:1, from candies.cpp:1: /usr/include/c++/10/bits/stl_iterator.h:1519:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator>(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorL>&)' 1519 | operator>(const move_iterator<_Iterator>& __x, | ^~~~~~~~ /usr/include/c++/10/bits/stl_iterator.h:1519:5: note: template argument deduction/substitution failed: candies.cpp:65:25: note: 'std::vector<int>' is not derived from 'const std::move_iterator<_IteratorL>' 65 | else if (r > c[i]) s[i] = cnt - r + c[i]; | ^ In file included from /usr/include/c++/10/vector:67, from candies.h:1, from candies.cpp:1: /usr/include/c++/10/bits/stl_vector.h:1943:5: note: candidate: 'template<class _Tp, class _Alloc> bool std::operator>(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)' 1943 | operator>(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) | ^~~~~~~~ /usr/include/c++/10/bits/stl_vector.h:1943:5: note: template argument deduction/substitution failed: candies.cpp:65:25: note: mismatched types 'const std::vector<_Tp, _Alloc>' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} 65 | else if (r > c[i]) s[i] = cnt - r + c[i]; | ^ In file included from /usr/include/c++/10/tuple:39, from /usr/include/c++/10/functional:54, from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13, from /usr/include/c++/10/algorithm:74, from candies.cpp:3: /usr/include/c++/10/array:293:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> bool std::operator>(const std::array<_Tp, _Nm>&, const std::array<_Tp, _Nm>&)' 293 | operator>(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) | ^~~~~~~~ /usr/include/c++/10/array:293:5: note: template argument deduction/substitution failed: candies.cpp:65:25: note: 'std::vector<int>' is not derived from 'const std::array<_Tp, _Nm>' 65 | else if (r > c[i]) s[i] = cnt - r + c[i]; | ^ In file included from /usr/include/c++/10/functional:54, from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13, from /usr/include/c++/10/algorithm:74, from candies.cpp:3: /usr/include/c++/10/tuple:1454:5: note: candidate: 'template<class ... _TElements, class ... _UElements> constexpr bool std::operator>(const std::tuple<_Tps ...>&, const std::tuple<_UTypes ...>&)' 1454 | operator>(const tuple<_TElements...>& __t, | ^~~~~~~~ /usr/include/c++/10/tuple:1454:5: note: template argument deduction/substitution failed: candies.cpp:65:25: note: 'std::vector<int>' is not derived from 'const std::tuple<_Tps ...>' 65 | else if (r > c[i]) s[i] = cnt - r + c[i]; | ^ In file included from /usr/include/c++/10/bits/node_handle.h:39, from /usr/include/c++/10/bits/hashtable.h:37, from /usr/include/c++/10/unordered_map:46, from /usr/include/c++/10/functional:61, from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13, from /usr/include/c++/10/algorithm:74, from candies.cpp:3: /usr/include/c++/10/optional:1011:5: note: candidate: 'template<class _Tp, class _Up> constexpr std::__optional_relop_t<decltype ((declval<_Tp>() > declval<_Up>()))> std::operator>(const std::optional<_Tp>&, const std::optional<_Up>&)' 1011 | operator>(const optional<_Tp>& __lhs, const optional<_Up>& __rhs) | ^~~~~~~~ /usr/include/c++/10/optional:1011:5: note: template argument deduction/substitution failed: candies.cpp:65:25: note: 'std::vector<int>' is not derived from 'const std::optional<_Tp>' 65 | else if (r > c[i]) s[i] = cnt - r + c[i]; | ^ In file included from /usr/include/c++/10/bits/node_handle.h:39, from /usr/include/c++/10/bits/hashtable.h:37, from /usr/include/c++/10/unordered_map:46, from /usr/include/c++/10/functional:61, from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13, from /usr/include/c++/10/algorithm:74, from candies.cpp:3: /usr/include/c++/10/optional:1081:5: note: candidate: 'template<class _Tp> constexpr bool std::operator>(const std::optional<_Tp>&, std::nullopt_t)' 1081 | operator>(const optional<_Tp>& __lhs, nullopt_t) noexcept | ^~~~~~~~ /usr/include/c++/10/optional:1081:5: note: template argument deduction/substitution failed: candies.cpp:65:25: note: 'std::vector<int>' is not derived from 'const std::optional<_Tp>' 65 | else if (r > c[i]) s[i] = cnt - r + c[i]; | ^ In file included from /usr/include/c++/10/bits/node_handle.h:39, from /usr/include/c++/10/bits/hashtable.h:37, from /usr/include/c++/10/unordered_map:46, from /usr/include/c++/10/functional:61, from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13, from /usr/include/c++/10/algorithm:74, from candies.cpp:3: /usr/include/c++/10/optional:1086:5: note: candidate: 'template<class _Tp> constexpr bool std::operator>(std::nullopt_t, const std::optional<_Tp>&)' 1086 | operator>(nullopt_t, const optional<_Tp>& /* __rhs */) noexcept | ^~~~~~~~ /usr/include/c++/10/optional:1086:5: note: template argument deduction/substitution failed: candies.cpp:65:25: note: mismatched types 'const std::optional<_Tp>' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} 65 | else if (r > c[i]) s[i] = cnt - r + c[i]; | ^ In file included from /usr/include/c++/10/bits/node_handle.h:39, from /usr/include/c++/10/bits/hashtable.h:37, from /usr/include/c++/10/unordered_map:46, from /