Pagini recente » Cod sursa (job #3167128) | Cod sursa (job #2024400) | Cod sursa (job #2810575) | Cod sursa (job #46071) | Cod sursa (job #3204838)
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
ifstream fin("cautbin.in");
ofstream fout("cautbin.out");
int v[100001],f[1001];
int main()
{
int n, i,m,j,x,OK=1,k=0,d,q=0,mij,t;
fin>>n;
for(i=1; i<=n; i++)
{
fin>>v[i];
}
fin>>m;
for(i=1; i<=m; i++)
{
fin>>t;
fin>>x;
if(t == 2) {
int st=1, dr=n;
while(st!=dr)
{
mij=(st+dr)/2;
if(v[mij]>=x)
{
dr=mij;
}
else st=mij+1;
}
fout<<st << endl;
} else if(t == 0) {
x ++;
int st=1, dr=n;
while(st!=dr)
{
mij=(st+dr)/2;
if(v[mij]>=x)
{
dr=mij;
}
else st=mij+1;
}
st --;
x --;
if(v[st] == x)
fout << st << endl;
else
fout << -1 << endl;
} else if(t == 1) {
x ++;
int st=1, dr=n;
while(st!=dr)
{
mij=(st+dr)/2;
if(v[mij]>=x)
{
dr=mij;
}
else st=mij+1;
}
st --;
fout << st << endl;
}
}
return 0;
}