Pagini recente » Cod sursa (job #2355529) | Cod sursa (job #2192164)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("cautbin.in");
ofstream fout("cautbin.out");
int n,x,m,c;
vector<int>elem;
vector<int>::iterator it;
int main()
{
fin>>n;
for(int i=1;i<=n;i++)
{
fin>>x;
elem.push_back(x);
}
fin>>m;
for(int i=1;i<=m;i++)
{
fin>>c>>x;
if(c==0)
{
it=upper_bound(elem.begin(),elem.end(),x)-1;
if(elem[it-elem.begin()]==x)
{
fout<<it-elem.begin()+1<<"\n";
continue;
}
fout<<-1<<"\n";
continue;
}
if(c==1)
{
it=upper_bound(elem.begin(),elem.end(),x);
fout<<it-elem.begin()<<"\n";
continue;
}
it=lower_bound(elem.begin(),elem.end(),x);
fout<<it-elem.begin()+1<<"\n";
}
return 0;
}