# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1203862 | ofoz | Gift Exchange (JOI24_ho_t4) | C++20 | 컴파일 에러 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
#define pi pair<int, int>
#define vi vector<int>
map<int, int> link;
bool query(int l, int r, vi& a, vi& b) {
vi B;
int mn = INT32_MAX;
set<int> A;
for (int i = l; i <= r; i++) {
B.push_back(b[i]);
A.insert(a[i]);
mn = min(mn, a[i]);
}
sort(B.rbegin(), B.rend());
for (int i = 0; i < B.size()-1; i++) {
int x = B[i];
bool pres = A.count(link[x]);
A.erase(link[x]);
auto it = A.upper_bound(x);
// cerr << x;
if (it == A.end()) return false;
// cerr << ' ' << *it << endl;
A.erase(it);
if (pres) A.insert(link[x]);
}
if (A.count(mn) && link[B.back()] == mn) return false;
return true;
}
// 12 14 16 17
// 11 13 9 3
void solve() {
int n;
cin >> n;
vector<int> a(n), b(n);
for (int &x : a) cin >> x;
for (int &x : b) cin >> x;
for (int i = 0; i < n; i++) {
link[b[i]] = a[i];
// cerr << b[i] << ' ' << link[b[i]] << endl;
}
int q;
cin >> q;
while (q--) {
int l, r;
cin >> l >> r;
l--;
r--;
bool res = query(l, r, a, b);
cout << (res ? "Yes" : "No") << '\n';
}
}
/*
when is a segment not gift exchangable?
*/
int main() {
solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp:5:15: error: 'std::map<int, int> link' redeclared as different kind of entity 5 | map<int, int> link; | ^~~~ In file included from /usr/include/x86_64-linux-gnu/bits/sigstksz.h:24, from /usr/include/signal.h:328, from /usr/include/c++/11/csignal:42, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:43, from Main.cpp:1: /usr/include/unistd.h:819:12: note: previous declaration 'int link(const char*, const char*)' 819 | extern int link (const char *__from, const char *__to) | ^~~~ Main.cpp: In function 'bool query(int, int, std::vector<int>&, std::vector<int>&)': Main.cpp:18:35: warning: pointer to a function used in arithmetic [-Wpointer-arith] 18 | bool pres = A.count(link[x]); | ^ Main.cpp:18:28: error: no matching function for call to 'std::set<int>::count(int (&)(const char*, const char*) noexcept)' 18 | bool pres = A.count(link[x]); | ~~~~~~~^~~~~~~~~ In file included from /usr/include/c++/11/set:61, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:87, from Main.cpp:1: /usr/include/c++/11/bits/stl_set.h:754:9: note: candidate: 'template<class _Kt> decltype (((const std::set<_Key, _Compare, _Alloc>*)this)->std::set<_Key, _Compare, _Alloc>::_M_t._M_count_tr(__x)) std::set<_Key, _Compare, _Alloc>::count(const _Kt&) const [with _Kt = _Kt; _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>]' 754 | count(const _Kt& __x) const | ^~~~~ /usr/include/c++/11/bits/stl_set.h:754:9: note: template argument deduction/substitution failed: /usr/include/c++/11/bits/stl_set.h: In substitution of 'template<class _Kt> decltype (((const std::set<int>*)this)->std::set<int>::_M_t.std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::_M_count_tr<_Kt, _Req>(__x)) std::set<int>::count<_Kt>(const _Kt&) const [with _Kt = int(const char*, const char*) noexcept]': Main.cpp:18:28: required from here /usr/include/c++/11/bits/stl_set.h:755:37: error: no matching function for call to 'std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::_M_count_tr(int (&)(const char*, const char*) noexcept) const' 755 | -> decltype(_M_t._M_count_tr(__x)) | ~~~~~~~~~~~~~~~~^~~~~ In file included from /usr/include/c++/11/map:60, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:81, from Main.cpp:1: /usr/include/c++/11/bits/stl_tree.h:1314:9: note: candidate: 'template<class _Kt, class _Req> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_count_tr(const _Kt&) const [with _Kt = _Kt; _Req = _Req; _Key = int; _Val = int; _KeyOfValue = std::_Identity<int>; _Compare = std::less<int>; _Alloc = std::allocator<int>]' 1314 | _M_count_tr(const _Kt& __k) const | ^~~~~~~~~~~ /usr/include/c++/11/bits/stl_tree.h:1314:9: note: template argument deduction/substitution failed: In file included from /usr/include/c++/11/string:48, from /usr/include/c++/11/bits/locale_classes.h:40, from /usr/include/c++/11/bits/ios_base.h:41, from /usr/include/c++/11/ios:42, from /usr/include/c++/11/istream:38, from /usr/include/c++/11/sstream:38, from /usr/include/c++/11/complex:45, from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from Main.cpp:1: /usr/include/c++/11/bits/stl_function.h: In substitution of 'template<class _Func, class _SfinaeType> using __has_is_transparent_t = typename std::__has_is_transparent<_Func, _SfinaeType>::type [with _Func = std::less<int>; _SfinaeType = int(const char*, const char*) noexcept]': /usr/include/c++/11/bits/stl_tree.h:1312:9: required by substitution of 'template<class _Kt> decltype (((const std::set<int>*)this)->std::set<int>::_M_t.std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::_M_count_tr<_Kt, _Req>(__x)) std::set<int>::count<_Kt>(const _Kt&) const [with _Kt = int(const char*, const char*) noexcept]' Main.cpp:18:28: required from here /usr/include/c++/11/bits/stl_function.h:1413:11: error: no type named 'type' in 'struct std::__has_is_transparent<std::less<int>, int(const char*, const char*) noexcept, void>' 1413 | using __has_is_transparent_t | ^~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/11/set:61, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:87, from Main.cpp:1: /usr/include/c++/11/bits/stl_set.h:748:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::size_type std::set<_Key, _Compare, _Alloc>::count(const key_type&) const [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; std::set<_Key, _Compare, _Alloc>::size_type = long unsigned int; std::set<_Key, _Compare, _Alloc>::key_type = int]' (near match) 748 | count(const key_type& __x) const | ^~~~~ /usr/include/c++/11/bits/stl_set.h:748:7: note: conversion of argument 1 would be ill-formed: Main.cpp:18:35: error: invalid conversion from 'int (*)(const char*, const char*) noexcept' to 'std::set<int>::key_type' {aka 'int'} [-fpermissive] 18 | bool pres = A.count(link[x]); | ~~~~~~^ | | | int (*)(const char*, const char*) noexcept Main.cpp:19:23: warning: pointer to a function used in arithmetic [-Wpointer-arith] 19 | A.erase(link[x]); | ^ Main.cpp:19:23: error: invalid conversion from 'int (*)(const char*, const char*) noexcept' to 'std::set<int>::key_type' {aka 'int'} [-fpermissive] 19 | A.erase(link[x]); | ~~~~~~^ | | | int (*)(const char*, const char*) noexcept In file included from /usr/include/c++/11/set:61, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:87, from Main.cpp:1: /usr/include/c++/11/bits/stl_set.h:684:29: note: initializing argument 1 of 'std::set<_Key, _Compare, _Alloc>::size_type std::set<_Key, _Compare, _Alloc>::erase(const key_type&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; std::set<_Key, _Compare, _Alloc>::size_type = long unsigned int; std::set<_Key, _Compare, _Alloc>::key_type = int]' 684 | erase(const key_type& __x) | ~~~~~~~~~~~~~~~~^~~ Main.cpp:25:34: warning: pointer to a function used in arithmetic [-Wpointer-arith] 25 | if (pres) A.insert(link[x]); | ^ Main.cpp:25:27: error: no matching function for call to 'std::set<int>::insert(int (&)(const char*, const char*) noexcept)' 25 | if (pres) A.insert(link[x]); | ~~~~~~~~^~~~~~~~~ In file included from /usr/include/c++/11/set:61, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:87, from Main.cpp:1: /usr/include/c++/11/bits/stl_set.h:566:9: note: candidate: 'template<class _InputIterator> void std::set<_Key, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator = _InputIterator; _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>]' 566 | insert(_InputIterator __first, _InputIterator __last) | ^~~~~~ /usr/include/c++/11/bits/stl_set.h:566:9: note: template argument deduction/substitution failed: Main.cpp:25:27: note: candidate expects 2 arguments, 1 provided 25 | if (pres) A.insert(link[x]); | ~~~~~~~~^~~~~~~~~ In file included from /usr/include/c++/11/set:61, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:87, from Main.cpp:1: /usr/include/c++/11/bits/stl_set.h:509:7: note: candidate: 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(const value_type&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other = std::allocator<int>; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key> = __gnu_cxx::__alloc_traits<std::allocator<int>, int>::rebind<int>; typename _Alloc::value_type = int; std::set<_Key, _Compare, _Alloc>::value_type = int]' (near match) 509 | insert(const value_type& __x) | ^~~~~~ /usr/include/c++/11/bits/stl_set.h:509:7: note: conversion of argument 1 would be ill-formed: Main.cpp:25:34: error: invalid conversion from 'int (*)(const char*, const char*) noexcept' to 'std::set<int>::value_type' {aka 'int'} [-fpermissive] 25 | if (pres) A.insert(link[x]); | ~~~~~~^ | | | int (*)(const char*, const char*) noexcept In file included from /usr/include/c++/11/set:61, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:87, from Main.cpp:1: /usr/include/c++/11/bits/stl_set.h:518:7: note: candidate: 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::value_type&&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other = std::allocator<int>; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key> = __gnu_cxx::__alloc_traits<std::allocator<int>, int>::rebind<int>; typename _Alloc::value_type = int; std::set<_Key, _Compare, _Alloc>::value_type = int]' (near match) 518 | insert(value_type&& __x) | ^~~~~~ /usr/include/c++/11/bits/stl_set.h:518:7: note: conversion of argument 1 would be ill-formed: Main.cpp:25:34: error: invalid conversion from 'int (*)(const char*, const char*) noexcept' to 'std::set<int>::value_type' {aka 'int'} [-fpermissive] 25 | if (pres) A.insert(link[x]); | ~~~~~~^ | | | int (*)(const char*, const char*) noexcept In file included from /usr/include/c++/11/set:61, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:87, from Main.cpp:1: /usr/include/c++/11/bits/stl_set.h:546:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::const_iterator, const value_type&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator; std::set<_Key, _Compare, _Alloc>::value_type = int]' 546 | insert(const_iterator __position, const value_type& __x) | ^~~~~~ /usr/include/c++/11/bits/stl_set.h:546:7: note: candidate expects 2 arguments, 1 provided /usr/include/c++/11/bits/stl_set.h:551:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::const_iterator, std::set<_Key, _Compare, _Alloc>::value_type&&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator; std::set<_Key, _Compare, _Alloc>::value_type = int]' 551 | insert(const_iterator __position, value_type&& __x) | ^~~~~~ /usr/include/c++/11/bits/stl_set.h:551:7: note: candidate expects 2 arguments, 1 provided /usr/include/c++/11/bits/stl_set.h:578:7: note: candidate: 'void std::set<_Key, _Compare, _Alloc>::insert(std::initializer_list<_Tp>) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>]' 578 | insert(initializer_list<value_type> __l) | ^~~~~~ /usr/include/c++/11/bits/stl_set.h:578:43: note: no known conversion for argument 1 from 'int(const char*, const char*) noexcept' to 'std::initializer_list<int>' 578 | insert(initializer_list<value_type> __l) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~ /usr/include/c++/11/bits/stl_set.h:598:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::insert_return_type std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::node_type&&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; std::set<_Key, _Compare, _Alloc>::insert_return_type = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::insert_return_type; std::set<_Key, _Compare, _Alloc>::node_type = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::node_type]' 598 | insert(node_type&& __nh) | ^~~~~~ /usr/include/c++/11/bits/stl_set.h:598:26: note: no known conversion for argument 1 from 'int(const char*, const char*) noexcept' to 'std::set<int>::node_type&&' {aka 'std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::node_type&&'} 598 | insert(node_type&& __nh) | ~~~~~~~~~~~~^~~~ /usr/include/c++/11/bits/stl_set.h:603:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::const_iterator, std::set<_Key, _Compare, _Alloc>::node_type&&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator; std::set<_Key, _Compare, _Alloc>::node_type = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::node_type]' 603 | insert(const_iterator __hint, node_type&& __nh) | ^~~~~~ /usr/include/c++/11/bits/stl_set.h:603:7: note: candidate expects 2 arguments, 1 provided Main.cpp:27:37: warning: pointer to a function used in arithmetic [-Wpointer-arith] 27 | if (A.count(mn) && link[B.back()] == mn) return false; | ^ Main.cpp:27:39: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] 27 | if (A.count(mn) && link[B.back()] == mn) return false; | ~~~~~~~~~~~~~~~^~~~~ Main.cpp: In function 'void solve()': Main.cpp:39:18: warning: pointer to a function used in arithmetic [-Wpointer-arith] 39 | link[b[i]] = a[i]; | ^ Main.cpp:39:20: error: assignment of read-only location '*(link, (link + ((sizetype)b.std::vector<int>::operator[](((std::vector<int>::size_type)i)))))' 39 | link[b[i]] = a[i];