Submission #769000

# Submission time Handle Problem Language Result Execution time Memory
769000 2023-06-29T04:34:11 Z boyliguanhan The Potion of Great Power (CEOI20_potion) C++17
Compilation error
0 ms 0 KB
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

const int NN = 100100;
int h[NN], n;
vector<int> adj[NN];

void init(int N, int D, int H[]) {
    n = N;
    for (int i = 0; i < N; i++)
        h[i] = H[i];
}

void curseChanges(int U, int A[], int B[]) {
    for (int i = 1; i <= U; i++) {
        int a = A[i - 1], b = B[i - 1];
        auto ita = find(adj[a].begin(), adj[a].end(), b);
        if (ita != adj[a].end()) {
            adj[a].erase(ita);
            adj[b].erase(find(adj[b].begin(), adj[b].end(), a));
        } else {
            adj[a].push_back(b);
            adj[b].push_back(a);
        }
    }
}

int calc(const vector<int>& a, const vector<int>& b) {
    int ans = 1e9;
    for (int i = 0, j = 0; i < (int)a.size() && j < (int)b.size(); i++) {
        if (a[i] > b[j])
            swap(a, b), swap(i, j);
        if (j)
            ans = min(ans, a[i] - b[j - 1]);
        ans =min(ans, a[i] - b[j]);
    }
    return ans;
}

int question(int x, int y, int v) {
    vector<int>& a = adj[x];
    vector<int>& b = adj[y];
    vector<int> c, d;
    for (auto i : a)
        c.push_back(h[i]);
    for (auto i : b)
        d.push_back(h[i]);
    sort(c.begin(), c.end());
    sort(d.begin(), d.end());
    return calc(c, d);
}

Compilation message

potion.cpp: In function 'int calc(const std::vector<int>&, const std::vector<int>&)':
potion.cpp:35:22: error: no matching function for call to 'swap(const std::vector<int>&, const std::vector<int>&)'
   35 |             swap(a, b), swap(i, j);
      |                      ^
In file included from /usr/include/c++/10/bits/nested_exception.h:40,
                 from /usr/include/c++/10/exception:148,
                 from /usr/include/c++/10/ios:39,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from potion.cpp:1:
/usr/include/c++/10/bits/move.h:189:5: note: candidate: 'template<class _Tp> std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&)'
  189 |     swap(_Tp& __a, _Tp& __b)
      |     ^~~~
/usr/include/c++/10/bits/move.h:189:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/10/bits/move.h:57,
                 from /usr/include/c++/10/bits/nested_exception.h:40,
                 from /usr/include/c++/10/exception:148,
                 from /usr/include/c++/10/ios:39,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from potion.cpp:1:
/usr/include/c++/10/type_traits: In substitution of 'template<bool _Cond, class _Tp> using __enable_if_t = typename std::enable_if::type [with bool _Cond = false; _Tp = void]':
/usr/include/c++/10/type_traits:2195:11:   required by substitution of 'template<class ... _Cond> using _Require = std::__enable_if_t<std::__and_< <template-parameter-1-1> >::value> [with _Cond = {std::__not_<std::__is_tuple_like<const std::vector<int, std::allocator<int> > > >, std::is_move_constructible<const std::vector<int, std::allocator<int> > >, std::is_move_assignable<const std::vector<int, std::allocator<int> > >}]'
/usr/include/c++/10/bits/move.h:189:5:   required by substitution of 'template<class _Tp> std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&) [with _Tp = const std::vector<int>]'
potion.cpp:35:22:   required from here
/usr/include/c++/10/type_traits:2192:11: error: no type named 'type' in 'struct std::enable_if<false, void>'
 2192 |     using __enable_if_t = typename enable_if<_Cond, _Tp>::type;
      |           ^~~~~~~~~~~~~
In file included from /usr/include/c++/10/bits/nested_exception.h:40,
                 from /usr/include/c++/10/exception:148,
                 from /usr/include/c++/10/ios:39,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from potion.cpp:1:
/usr/include/c++/10/bits/move.h:213:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> std::__enable_if_t<std::__is_swappable<_Tp>::value> std::swap(_Tp (&)[_Nm], _Tp (&)[_Nm])'
  213 |     swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
      |     ^~~~
/usr/include/c++/10/bits/move.h:213:5: note:   template argument deduction/substitution failed:
potion.cpp:35:22: note:   mismatched types '_Tp [_Nm]' and 'const std::vector<int>'
   35 |             swap(a, b), swap(i, j);
      |                      ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from potion.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:533:5: note: candidate: 'template<class _T1, class _T2> typename std::enable_if<std::__and_<std::__is_swappable<_T1>, std::__is_swappable<_T2> >::value>::type std::swap(std::pair<_T1, _T2>&, std::pair<_T1, _T2>&)'
  533 |     swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
      |     ^~~~
/usr/include/c++/10/bits/stl_pair.h:533:5: note:   template argument deduction/substitution failed:
potion.cpp:35:22: note:   types 'std::pair<_T1, _T2>' and 'const std::vector<int>' have incompatible cv-qualifiers
   35 |             swap(a, b), swap(i, j);
      |                      ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from potion.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:541:5: note: candidate: 'template<class _T1, class _T2> typename std::enable_if<(! std::__and_<std::__is_swappable<_T1>, std::__is_swappable<_T2> >::value)>::type std::swap(std::pair<_T1, _T2>&, std::pair<_T1, _T2>&)' (deleted)
  541 |     swap(pair<_T1, _T2>&, pair<_T1, _T2>&) = delete;
      |     ^~~~
/usr/include/c++/10/bits/stl_pair.h:541:5: note:   template argument deduction/substitution failed:
potion.cpp:35:22: note:   types 'std::pair<_T1, _T2>' and 'const std::vector<int>' have incompatible cv-qualifiers
   35 |             swap(a, b), swap(i, j);
      |                      ^
In file included from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from potion.cpp:1:
/usr/include/c++/10/bits/basic_string.h:6420:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> void std::swap(std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&, std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 6420 |     swap(basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~
/usr/include/c++/10/bits/basic_string.h:6420:5: note:   template argument deduction/substitution failed:
potion.cpp:35:22: note:   types 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' and 'const std::vector<int>' have incompatible cv-qualifiers
   35 |             swap(a, b), swap(i, j);
      |                      ^
In file included from /usr/include/c++/10/vector:67,
                 from potion.cpp:2:
/usr/include/c++/10/bits/stl_vector.h:1962:5: note: candidate: 'template<class _Tp, class _Alloc> void std::swap(std::vector<_Tp, _Alloc>&, std::vector<_Tp, _Alloc>&)'
 1962 |     swap(vector<_Tp, _Alloc>& __x, vector<_Tp, _Alloc>& __y)
      |     ^~~~
/usr/include/c++/10/bits/stl_vector.h:1962:5: note:   template argument deduction/substitution failed:
potion.cpp:35:22: note:   types 'std::vector<_Tp, _Alloc>' and 'const std::vector<int>' have incompatible cv-qualifiers
   35 |             swap(a, b), swap(i, j);
      |                      ^
In file included from /usr/include/c++/10/vector:68,
                 from potion.cpp:2:
/usr/include/c++/10/bits/stl_bvector.h:118:3: note: candidate: 'void std::swap(std::_Bit_reference, std::_Bit_reference)'
  118 |   swap(_Bit_reference __x, _Bit_reference __y) noexcept
      |   ^~~~
/usr/include/c++/10/bits/stl_bvector.h:118:23: note:   no known conversion for argument 1 from 'const std::vector<int>' to 'std::_Bit_reference'
  118 |   swap(_Bit_reference __x, _Bit_reference __y) noexcept
      |        ~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_bvector.h:126:3: note: candidate: 'void std::swap(std::_Bit_reference, bool&)'
  126 |   swap(_Bit_reference __x, bool& __y) noexcept
      |   ^~~~
/usr/include/c++/10/bits/stl_bvector.h:126:23: note:   no known conversion for argument 1 from 'const std::vector<int>' to 'std::_Bit_reference'
  126 |   swap(_Bit_reference __x, bool& __y) noexcept
      |        ~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_bvector.h:134:3: note: candidate: 'void std::swap(bool&, std::_Bit_reference)'
  134 |   swap(bool& __x, _Bit_reference __y) noexcept
      |   ^~~~
/usr/include/c++/10/bits/stl_bvector.h:134:14: note:   no known conversion for argument 1 from 'const std::vector<int>' to 'bool&'
  134 |   swap(bool& __x, _Bit_reference __y) noexcept
      |        ~~~~~~^~~
In file included from /usr/include/c++/10/bits/node_handle.h:39,
                 from /usr/include/c++/10/bits/stl_tree.h:72,
                 from /usr/include/c++/10/set:60,
                 from potion.cpp:3:
/usr/include/c++/10/optional:1196:5: note: candidate: 'template<class _Tp> std::enable_if_t<(is_move_constructible_v<_Tp> && is_swappable_v<_Tp>)> std::swap(std::optional<_Tp>&, std::optional<_Tp>&)'
 1196 |     swap(optional<_Tp>& __lhs, optional<_Tp>& __rhs)
      |     ^~~~
/usr/include/c++/10/optional:1196:5: note:   template argument deduction/substitution failed:
potion.cpp:35:22: note:   types 'std::optional<_Tp>' and 'const std::vector<int>' have incompatible cv-qualifiers
   35 |             swap(a, b), swap(i, j);
      |                      ^
In file included from /usr/include/c++/10/bits/node_handle.h:39,
                 from /usr/include/c++/10/bits/stl_tree.h:72,
                 from /usr/include/c++/10/set:60,
                 from potion.cpp:3:
/usr/include/c++/10/optional:1202:5: note: candidate: 'template<class _Tp> std::enable_if_t<(!(is_move_constructible_v<_Tp> && is_swappable_v<_Tp>))> std::swap(std::optional<_Tp>&, std::optional<_Tp>&)' (deleted)
 1202 |     swap(optional<_Tp>&, optional<_Tp>&) = delete;
      |     ^~~~
/usr/include/c++/10/optional:1202:5: note:   template argument deduction/substitution failed:
potion.cpp:35:22: note:   types 'std::optional<_Tp>' and 'const std::vector<int>' have incompatible cv-qualifiers
   35 |             swap(a, b), swap(i, j);
      |                      ^
In file included from /usr/include/c++/10/set:60,
                 from potion.cpp:3:
/usr/include/c++/10/bits/stl_tree.h:1655:5: note: candidate: 'template<class _Key, class _Val, class _KeyOfValue, class _Compare, class _Alloc> void std::swap(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&, std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&)'
 1655 |     swap(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
      |     ^~~~
/usr/include/c++/10/bits/stl_tree.h:1655:5: note:   template argument deduction/substitution failed:
potion.cpp:35:22: note:   types 'std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>' and 'const std::vector<int>' have incompatible cv-qualifiers
   35 |             swap(a, b), swap(i, j);
      |                      ^
In file included from /usr/include/c++/10/set:61,
                 from potion.cpp:3:
/usr/include/c++/10/bits/stl_set.h:1059:5: note: candidate: 'template<class _Key, class _Compare, class _Alloc> void std::swap(std::set<_Key, _Compare, _Allocator>&, std::set<_Key, _Compare, _Allocator>&)'
 1059 |     swap(set<_Key, _Compare, _Alloc>& __x, set<_Key, _Compare, _Alloc>& __y)
      |     ^~~~
/usr/include/c++/10/bits/stl_set.h:1059:5: note:   template argument deduction/substitution failed:
potion.cpp:35:22: note:   types 'std::set<_Key, _Compare, _Allocator>' and 'const std::vector<int>' have incompatible cv-qualifiers
   35 |             swap(a, b), swap(i, j);
      |                      ^
In file included from /usr/include/c++/10/set:62,
                 from potion.cpp:3:
/usr/include/c++/10/bits/stl_multiset.h:1045:5: note: candidate: 'template<class _Key, class _Compare, class _Alloc> void std::swap(std::multiset<_Key, _Compare, _Allocator>&, std::multiset<_Key, _Compare, _Allocator>&)'
 1045 |     swap(multiset<_Key, _Compare, _Alloc>& __x,
      |     ^~~~
/usr/include/c++/10/bits/stl_multiset.h:1045:5: note:   template argument deduction/substitution failed:
potion.cpp:35:22: note:   types 'std::multiset<_Key, _Compare, _Allocator>' and 'const std::vector<int>' have incompatible cv-qualifiers
   35 |             swap(a, b), swap(i, j);
      |                      ^
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 potion.cpp:4:
/usr/include/c++/10/array:321:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> typename std::enable_if<typename std::__array_traits<_Tp, _Nm>::_Is_swappable::value>::type std::swap(std::array<_Tp, _Nm>&, std::array<_Tp, _Nm>&)'
  321 |     swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two)
      |     ^~~~
/usr/include/c++/10/array:321:5: note:   template argument deduction/substitution failed:
potion.cpp:35:22: note:   types 'std::array<_Tp, _Nm>' and 'const std::vector<int>' have incompatible cv-qualifiers
   35 |             swap(a, b), swap(i, j);
      |                      ^
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 potion.cpp:4:
/usr/include/c++/10/array:329:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> typename std::enable_if<(! typename std::__array_traits<_Tp, _Nm>::_Is_swappable::value)>::type std::swap(std::array<_Tp, _Nm>&, std::array<_Tp, _Nm>&)' (deleted)
  329 |     swap(array<_Tp, _Nm>&, array<_Tp, _Nm>&) = delete;
      |     ^~~~
/usr/include/c++/10/array:329:5: note:   template argument deduction/substitution failed:
potion.cpp:35:22: note:   types 'std::array<_Tp, _Nm>' and 'const std::vector<int>' have incompatible cv-qualifiers
   35 |             swap(a, b), swap(i, j);
      |                      ^
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 potion.cpp:4:
/usr/include/c++/10/tuple:1629:5: note: candidate: 'template<class ... _Elements> typename std::enable_if<std::__and_<std::__is_swappable<_Elements>...>::value>::type std::swap(std::tuple<_Tps ...>&, std::tuple<_Tps ...>&)'
 1629 |     swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y)
      |     ^~~~
/usr/include/c++/10/tuple:1629:5: note:   template argument deduction/substitution failed:
potion.cpp:35:22: note:   types 'std::tuple<_Tps ...>' and 'const std::vector<int>' have incompatible cv-qualifiers
   35 |             swap(a, b), swap(i, j);
      |                      ^
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 potion.cpp:4:
/usr/include/c++/10/tuple:1637:5: note: candidate: 'template<class ... _Elements> typename std::enable_if<(! std::__and_<std::__is_swappable<_Elements>...>::value)>::type std::swap(std::tuple<_Tps ...>&, std::tuple<_Tps ...>&)' (deleted)
 1637 |     swap(tuple<_Elements...>&, tuple<_Elements...>&) = delete;
      |     ^~~~
/usr/include/c++/10/tuple:1637:5: note:   template argument deduction/substitution failed:
potion.cpp:35:22: note:   types 'std::tuple<_Tps ...>' and 'const std::vector<int>' have incompatible cv-qualifiers
   35 |             swap(a, b), swap(i, j);
      |                      ^
In file included from /usr/include/c++/10/functional:59,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from potion.cpp:4:
/usr/include/c++/10/bits/std_function.h:720:5: note: candidate: 'template<class _Res, class ... _Args> void std::swap(std::function<_Res(_ArgTypes ...)>&, std::function<_Res(_ArgTypes ...)>&)'
  720 |     swap(function<_Res(_Args...)>& __x, function<_Res(_Args...)>& __y) noexcept
      |     ^~~~
/usr/include/c++/10/bits/std_function.h:720:5: note:   template argument deduction/substitution failed:
potion.cpp:35:22: note:   types 'std::function<_Res(_ArgTypes ...)>' and 'const std::vector<int>' have incompatible cv-qualifiers
   35 |             swap(a, b), swap(i, j);
      |                      ^
In file included from /usr/include/c++/10/unordered_map:47,
                 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 potion.cpp:4:
/usr/include/c++/10/bits/unordered_map.h:2076:5: note: candidate: 'template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> void std::swap(std::unordered_map<_Key1, _Tp1, _Hash1, _Pred1, _Alloc1>&, std::unordered_map<_Key1, _Tp1, _Hash1, _Pred1, _Alloc1>&)'
 2076 |     swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
      |     ^~~~
/usr/include/c++/10/bits/unordered_map.h:2076:5: note:   template argument deduction/substitution failed:
potion.cpp:35:22: note:   types 'std::unordered_map<_Key1, _Tp1, _Hash1, _Pred1, _Alloc1>' and 'const std::vector<int>' have incompatible cv-qualifiers
   35 |             swap(a, b), swap(i, j);
      |                      ^
In file included from /usr/include/c++/10/unordered_map:47,
                 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 potion.cpp:4:
/usr/include/c++/10/bits/unordered_map.h:2083:5: note: candidate: 'template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> void std::swap(std::unordered_multimap<_Key1, _Tp1, _Hash1, _Pred1, _Alloc1>&, std::unordered_multimap<_Key1, _Tp1, _Hash1, _Pred1, _Alloc1>&)'
 2083 |     swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
      |     ^~~~
/usr/include/c++/10/bits/unordered_map.h:2083:5: note:   template argument deduction/substitution failed:
potion.cpp:35:22: note:   types 'std::unordered_multimap<_Key1, _Tp1, _Hash1, _Pred1, _Alloc1>' and 'const std::vector<int>' have incompatible cv-qualifiers
   35 |             swap(a, b), swap(i, j);
      |                      ^