Pagini recente » Cod sursa (job #1807444) | Cod sursa (job #1528000) | Cod sursa (job #537087) | Cod sursa (job #3147498) | Cod sursa (job #340429)
Cod sursa(job #340429)
#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(); iend=v.end();
--ibegin; ++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 if( 1 == q )
{--s.first;
if( s.first != ibegin ) out<<s.first->second.second;
//else out<<"Error";
}
else if( 2 == q )
{++s.second;
if( s.second != iend ) out<<s.second->second.first;
//else out<<"Error";
}
}
else {
if( q <= 1 ) out<<v[x].second;
else out<<v[x].first;
}
out<<'\n';
}
return 0;
}