Pagini recente » Cod sursa (job #2189910) | Cod sursa (job #3262105) | Cod sursa (job #2300242) | Cod sursa (job #898188) | Cod sursa (job #340462)
Cod sursa(job #340462)
#include <fstream>
#include <map>
#include <utility>
using namespace std;
ifstream in;
ofstream out;
map< long, pair< long, long > >v;
map< long, pair< long, long > >::const_iterator ibegin,iend;
pair< map< long, pair< long, long > >::const_iterator, map< long, pair< long, long > >::const_iterator > s;
int main()
{long i,N,number,q,x;
in.open("cautbin.in");
in>>N;
for( i=1; i<=N; ++i )
{
in>>number;
if( !v[number].first || v[number].first > i ) v[number].first=i;
if( !v[number].second || v[number].second < i ) v[number].second=i;
}
in>>N;
ibegin=v.begin(); //--ibegin;
iend=v.end(); //++iend;
out.open("cautbin.out");
while( N-- )
{
in>>q>>x;
s=v.equal_range(x);
if( s.second == s.first )
{
if( 0 == q ) out<<"-1";
else {
v[x].first=v[x].second=0;
s=v.equal_range(x);
if( 1 == q )
{
--s.first;
out<<s.first->second.second;
}
else if( 2 == q )
{
out<<s.second->second.first;
}
v.erase(x);
}
}
else {
if( q <= 1 ) out<<v[x].second;
else out<<v[x].first;
}
out<<'\n';
}
return 0;
}