Pagini recente » Cod sursa (job #580967) | Cod sursa (job #2008829) | Cod sursa (job #2730187) | Cod sursa (job #1777821) | Cod sursa (job #1114184)
#include <stdio.h>
#include <map>
using namespace std;
multimap<int,int > M;
multimap<int,int >::iterator it,it2;
int N;
int main()
{
freopen("cautbin.in","r",stdin);
freopen("cautbin.out","w",stdout);
scanf("%d",&N);
int X;
for(register int i=1;i<=N;++i){
scanf("%d",&X);
M.insert( make_pair(X,i) );
}
int k,a,b;
scanf("%d",&k);
for(register int i=1;i<=k;++i){
scanf("%d%d",&a,&b);
switch( a ){
case 0:{
it= M .find( b );
it2=it;
if( it != M.end() ){
while( (++it)->first == it2->first ) ;
--it;
}
it2=M.begin();
it2--;
if( it!=M.end() && it !=it2 && it->first>0)
printf("%d\n", it->second );
else printf("-1\n");
break;
}
case 1:{
it=M.find(b);
it2=it;
if( it != M.end() ){
while( (++it)->first == it2->first ) ;
--it;
}
else{
it=M.upper_bound(b);
--it;
}
it2=M.begin();
it2--;
if( it!=M.end() && it !=it2 && it->first>0)
printf("%d\n", it->second );
else printf("-1\n");
break;
}
case 2:{
it=M.upper_bound(b);
if( it->second > M.find(b)->second ){
it= M .find( b );
}
it2=M.begin();
it2--;
if( it!=M.end() && it !=it2 && it->first>0)
printf("%d\n", it->second );
else printf("-1\n");
break;
}
}
}
return 0;
}