Pagini recente » Cod sursa (job #2703462) | Cod sursa (job #2944328) | Cod sursa (job #2447392) | Cod sursa (job #1707300) | Cod sursa (job #197796)
Cod sursa(job #197796)
#include <stdio.h>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <algorithm>
#include <utility>
#include <string>
#include <functional>
#include <sstream>
#include <fstream>
using namespace std;
#define FOR(i,a,b) for (typeof a i=a;i<=b;i++)
#define fori(it,v) for (typeof ((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define mp make_pair
#define fs first
#define ss second
#define all(c) c.begin(),c.end()
#define pf push_front
#define popb pop_back
#define popf pop_front
ofstream fout;
ostringstream out;
istringstream in;
void initializare_citire()
{
ifstream fin;
fin.open("cautbin.in",ifstream::in);
fout.open("cautbin.out",ofstream::out);
string aux;
getline(fin,aux,'\0');
in.str(aux);
fin.close();
}
void scriere()
{
fout<<out.str();
fout.close();
}
vector<int>a;
int n,m,x,y;
vector<int>::iterator t;
int main()
{
initializare_citire();
in>>n;
a.reserve(n);
FOR(i,1,n)
{
in>>x;
a.pb(x);
}
in>>m;
FOR(i,1,m)
{
in>>x>>y;
if (x==0)
{
t=upper_bound(all(a),y);
if (*(t-1)==y)
out<<t-a.begin()<<'\n';
else
out<<-1<<'\n';
}
if (x==1)
{
t=lower_bound(all(a),y);
if (*t!=y)
t--;
out<<t-a.begin()+1<<'\n';
}
if (x==2)
{
t=upper_bound(all(a),y);
if (*(t-1)==y)
t--;
out<<t-a.begin()+1<<'\n';
}
}
scriere();
return 0;
}