Submission #151456

# Submission time Handle Problem Language Result Execution time Memory
151456 2019-09-03T09:13:27 Z babo Lokahian Relics (FXCUP4_lokahia) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define x first
#define y second

using namespace std;

int CollectRelics(int,int);

multiset<pair<int,int> >st,st2,st3;

int FindBase(int N){
	int i;
	for(i=0;i<N;i++)
	{
		st.insert(make_pair(1,i));
	}
	while(st.size()>=2)
	{
		//printf("sz %d , %d %d %d %d %d\n",st.size(),st.begin()->y,next(st.begin())->y,st.begin()->x,next(st.begin())->x);
		//printf(" %d\n",CollectRelics(st.begin()->y,next(st.begin())->y));
		if(st.begin()->x==next(st.begin())->x)
		{
			int temp=st.begin()->y==next(st.begin())->y?st.begin()->y:CollectRelics(st.begin()->y,next(st.begin())->y);
			if(temp!=-1)
			{
				//printf("%d\n",st.size());
				st.erase(next(st.begin()));
				st.insert(make_pair(st.begin()->x*2,temp));
				st.erase(st.begin());	
				//printf("%d\n",st.size());
			}
			else
			{
				st2.insert(*st.begin());
				st.erase(st.begin());
				st2.insert(*st.begin());
				st.erase(st.begin());
			}
		}
		else
		{
			st3.insert(*st.begin());
			st.erase(st.begin());
		}
	}
	int las,ans;
	if(st.empty())
	{
		if(st3.empty())
			return -1;
		else
		{
			las=st3.rbegin()->y;
			ans=st3.rbegin()->x;
			st3.erase(st3.rbegin());
		}
	}
	else
	{
		las=st.begin()->y;
		ans=st.begin()->x;
		st.erase(st.begin());
	}
	for(multiset<pair<int,int> >::iterator it=st2.begin();it!=st2.end();it++)
	{
		int temp=las==it->y?las:CollectRelics(las,it->y);
		if(temp!=-1)
		{
			las=temp;
			ans+=it->x;
		}
	}
	for(multiset<pair<int,int> >::iterator it=st3.begin();it!=st3.end();it++)
	{
		int temp=las==it->y?las:CollectRelics(las,it->y);
		if(temp!=-1)
		{
			las=temp;
			ans+=it->x;
		}
	}
	if(ans>N/2)
		return las;
	return -1;
}

Compilation message

lokahia.cpp: In function 'int FindBase(int)':
lokahia.cpp:55:26: error: no matching function for call to 'std::multiset<std::pair<int, int> >::erase(std::multiset<std::pair<int, int> >::reverse_iterator)'
    st3.erase(st3.rbegin());
                          ^
In file included from /usr/include/c++/7/set:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:87,
                 from lokahia.cpp:1:
/usr/include/c++/7/bits/stl_multiset.h:629:7: note: candidate: std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::erase(std::multiset<_Key, _Compare, _Alloc>::const_iterator) [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> >]
       erase(const_iterator __position)
       ^~~~~
/usr/include/c++/7/bits/stl_multiset.h:629:7: note:   no known conversion for argument 1 from 'std::multiset<std::pair<int, int> >::reverse_iterator {aka std::reverse_iterator<std::_Rb_tree_const_iterator<std::pair<int, int> > >}' to 'std::multiset<std::pair<int, int> >::const_iterator {aka std::_Rb_tree_const_iterator<std::pair<int, int> >}'
/usr/include/c++/7/bits/stl_multiset.h:659:7: note: candidate: std::multiset<_Key, _Compare, _Alloc>::size_type std::multiset<_Key, _Compare, _Alloc>::erase(const key_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>::size_type = long unsigned int; std::multiset<_Key, _Compare, _Alloc>::key_type = std::pair<int, int>]
       erase(const key_type& __x)
       ^~~~~
/usr/include/c++/7/bits/stl_multiset.h:659:7: note:   no known conversion for argument 1 from 'std::multiset<std::pair<int, int> >::reverse_iterator {aka std::reverse_iterator<std::_Rb_tree_const_iterator<std::pair<int, int> > >}' to 'const key_type& {aka const std::pair<int, int>&}'
/usr/include/c++/7/bits/stl_multiset.h:681:7: note: candidate: std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::erase(std::multiset<_Key, _Compare, _Alloc>::const_iterator, std::multiset<_Key, _Compare, _Alloc>::const_iterator) [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> >]
       erase(const_iterator __first, const_iterator __last)
       ^~~~~
/usr/include/c++/7/bits/stl_multiset.h:681:7: note:   candidate expects 2 arguments, 1 provided