Submission #276940

#TimeUsernameProblemLanguageResultExecution timeMemory
276940eohomegrownappsRoller Coaster Railroad (IOI16_railroad)C++14
Compilation error
0 ms0 KiB
#include "railroad.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) { int n = (int) s.size(); multiset<pair<int,int>> lrset; multiset<pair<int,int>> rlset; for (int i = 0; i<n; i++){ lrset.insert({s[i],t[i]}); rlset.insert({t[i],s[i]}); } while (lrset.size()>1){ cout<<'\n'; for (auto p : lrset){ cout<<p.first<<' '<<p.second<<'\n'; } auto el = lrset.begin(); int firstl = el->first; auto smallestrpair = rlset.lower_bound({firstl+1,-1}); if (smallestrpair!=rlset.begin()&&*prev(smallestrpair,1)==make_pair(el->second,el->first)){ smallestrpair = rlset.lower_bound({el->second,el->first-1}); } if (smallestrpair==rlset.begin()){ el = next(el,1); firstl = el->first; smallestrpair = rlset.lower_bound({firstl+1,-1}); if (smallestrpair!=rlset.begin()&&*prev(smallestrpair,1)==make_pair(el->second,el->first)){ smallestrpair = rlset.lower_bound({el->second,el->first-1}); } if (smallestrpair==rlset.begin()){ return 1; } } smallestrpair = prev(smallestrpair,1); //merge el with smallestrpair int fpairl = el->first; int fpairr = el->second; int spairl = smallestrpair->second; int spairr = smallestrpair->first; //cout<<fpairl<<' '<<fpairr<<' '<<spairl<<' '<<spairr<<'\n'; lrset.erase(lrset.find({fpairl,fpairr})); rlset.erase(rlset.find({fpairr,fpairl})); lrset.erase(lrset.find({spairl,spairr})); rlset.erase(rlset.find({spairr,spairl})); lrset.insert(lrset.find({spairl,fpairr})); rlset.insert(rlset.find({fpairr,spairl})); } return 0; }

Compilation message (stderr)

railroad.cpp: In function 'long long int plan_roller_coaster(std::vector<int>, std::vector<int>)':
railroad.cpp:47:46: error: no matching function for call to 'std::multiset<std::pair<int, int> >::insert(std::multiset<std::pair<int, int> >::iterator)'
   47 |      lrset.insert(lrset.find({spairl,fpairr}));
      |                                              ^
In file included from /usr/include/c++/9/set:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:87,
                 from railroad.cpp:2:
/usr/include/c++/9/bits/stl_multiset.h:502:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(const value_type&) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; std::multiset<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >; std::multiset<_Key, _Compare, _Alloc>::value_type = std::pair<int, int>]'
  502 |       insert(const value_type& __x)
      |       ^~~~~~
/usr/include/c++/9/bits/stl_multiset.h:502:32: note:   no known conversion for argument 1 from 'std::multiset<std::pair<int, int> >::iterator' {aka 'std::_Rb_tree_const_iterator<std::pair<int, int> >'} to 'const value_type&' {aka 'const std::pair<int, int>&'}
  502 |       insert(const value_type& __x)
      |              ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_multiset.h:507:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(std::multiset<_Key, _Compare, _Alloc>::value_type&&) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; std::multiset<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >; std::multiset<_Key, _Compare, _Alloc>::value_type = std::pair<int, int>]'
  507 |       insert(value_type&& __x)
      |       ^~~~~~
/usr/include/c++/9/bits/stl_multiset.h:507:27: note:   no known conversion for argument 1 from 'std::multiset<std::pair<int, int> >::iterator' {aka 'std::_Rb_tree_const_iterator<std::pair<int, int> >'} to 'std::multiset<std::pair<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
  507 |       insert(value_type&& __x)
      |              ~~~~~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_multiset.h:532:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(std::multiset<_Key, _Compare, _Alloc>::const_iterator, const value_type&) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; std::multiset<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >; std::multiset<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >; std::multiset<_Key, _Compare, _Alloc>::value_type = std::pair<int, int>]'
  532 |       insert(const_iterator __position, const value_type& __x)
      |       ^~~~~~
/usr/include/c++/9/bits/stl_multiset.h:532:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/9/bits/stl_multiset.h:537:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(std::multiset<_Key, _Compare, _Alloc>::const_iterator, std::multiset<_Key, _Compare, _Alloc>::value_type&&) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; std::multiset<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >; std::multiset<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >; std::multiset<_Key, _Compare, _Alloc>::value_type = std::pair<int, int>]'
  537 |       insert(const_iterator __position, value_type&& __x)
      |       ^~~~~~
/usr/include/c++/9/bits/stl_multiset.h:537:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/9/bits/stl_multiset.h:551:2: note: candidate: 'template<class _InputIterator> void std::multiset<_Key, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator = _InputIterator; _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >]'
  551 |  insert(_InputIterator __first, _InputIterator __last)
      |  ^~~~~~
/usr/include/c++/9/bits/stl_multiset.h:551:2: note:   template argument deduction/substitution failed:
railroad.cpp:47:46: note:   candidate expects 2 arguments, 1 provided
   47 |      lrset.insert(lrset.find({spairl,fpairr}));
      |                                              ^
In file included from /usr/include/c++/9/set:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:87,
                 from railroad.cpp:2:
/usr/include/c++/9/bits/stl_multiset.h:563:7: note: candidate: 'void std::multiset<_Key, _Compare, _Alloc>::insert(std::initializer_list<_Tp>) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >]'
  563 |       insert(initializer_list<value_type> __l)
      |       ^~~~~~
/usr/include/c++/9/bits/stl_multiset.h:563:43: note:   no known conversion for argument 1 from 'std::multiset<std::pair<int, int> >::iterator' {aka 'std::_Rb_tree_const_iterator<std::pair<int, int> >'} to 'std::initializer_list<std::pair<int, int> >'
  563 |       insert(initializer_list<value_type> __l)
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
railroad.cpp:48:46: error: no matching function for call to 'std::multiset<std::pair<int, int> >::insert(std::multiset<std::pair<int, int> >::iterator)'
   48 |      rlset.insert(rlset.find({fpairr,spairl}));
      |                                              ^
In file included from /usr/include/c++/9/set:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:87,
                 from railroad.cpp:2:
/usr/include/c++/9/bits/stl_multiset.h:502:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(const value_type&) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; std::multiset<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >; std::multiset<_Key, _Compare, _Alloc>::value_type = std::pair<int, int>]'
  502 |       insert(const value_type& __x)
      |       ^~~~~~
/usr/include/c++/9/bits/stl_multiset.h:502:32: note:   no known conversion for argument 1 from 'std::multiset<std::pair<int, int> >::iterator' {aka 'std::_Rb_tree_const_iterator<std::pair<int, int> >'} to 'const value_type&' {aka 'const std::pair<int, int>&'}
  502 |       insert(const value_type& __x)
      |              ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_multiset.h:507:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(std::multiset<_Key, _Compare, _Alloc>::value_type&&) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; std::multiset<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >; std::multiset<_Key, _Compare, _Alloc>::value_type = std::pair<int, int>]'
  507 |       insert(value_type&& __x)
      |       ^~~~~~
/usr/include/c++/9/bits/stl_multiset.h:507:27: note:   no known conversion for argument 1 from 'std::multiset<std::pair<int, int> >::iterator' {aka 'std::_Rb_tree_const_iterator<std::pair<int, int> >'} to 'std::multiset<std::pair<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
  507 |       insert(value_type&& __x)
      |              ~~~~~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_multiset.h:532:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(std::multiset<_Key, _Compare, _Alloc>::const_iterator, const value_type&) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; std::multiset<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >; std::multiset<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >; std::multiset<_Key, _Compare, _Alloc>::value_type = std::pair<int, int>]'
  532 |       insert(const_iterator __position, const value_type& __x)
      |       ^~~~~~
/usr/include/c++/9/bits/stl_multiset.h:532:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/9/bits/stl_multiset.h:537:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(std::multiset<_Key, _Compare, _Alloc>::const_iterator, std::multiset<_Key, _Compare, _Alloc>::value_type&&) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; std::multiset<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >; std::multiset<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >; std::multiset<_Key, _Compare, _Alloc>::value_type = std::pair<int, int>]'
  537 |       insert(const_iterator __position, value_type&& __x)
      |       ^~~~~~
/usr/include/c++/9/bits/stl_multiset.h:537:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/9/bits/stl_multiset.h:551:2: note: candidate: 'template<class _InputIterator> void std::multiset<_Key, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator = _InputIterator; _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >]'
  551 |  insert(_InputIterator __first, _InputIterator __last)
      |  ^~~~~~
/usr/include/c++/9/bits/stl_multiset.h:551:2: note:   template argument deduction/substitution failed:
railroad.cpp:48:46: note:   candidate expects 2 arguments, 1 provided
   48 |      rlset.insert(rlset.find({fpairr,spairl}));
      |                                              ^
In file included from /usr/include/c++/9/set:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:87,
                 from railroad.cpp:2:
/usr/include/c++/9/bits/stl_multiset.h:563:7: note: candidate: 'void std::multiset<_Key, _Compare, _Alloc>::insert(std::initializer_list<_Tp>) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >]'
  563 |       insert(initializer_list<value_type> __l)
      |       ^~~~~~
/usr/include/c++/9/bits/stl_multiset.h:563:43: note:   no known conversion for argument 1 from 'std::multiset<std::pair<int, int> >::iterator' {aka 'std::_Rb_tree_const_iterator<std::pair<int, int> >'} to 'std::initializer_list<std::pair<int, int> >'
  563 |       insert(initializer_list<value_type> __l)
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~