Pagini recente » Cod sursa (job #938418) | Cod sursa (job #2362) | Cod sursa (job #104884) | Cod sursa (job #553909) | Cod sursa (job #2551289)
#include <bits/stdc++.h>
using namespace std;
ifstream in("cautbin.in");
ofstream out("cautbin.out");
int n, m, v[100001];
int cautbin(int val)
{
int poz = 0;
for(int p = n/2; p; p/=2)
while(p + poz <=n && v[poz+p]<=val)
poz+=p;
return poz;
}
int main()
{
in>>n;
for(int i=1; i<=n; i++)
in>>v[i];
in>>m;
for(int x, y, j; m; m--){
in>>y>>x;
switch(y)
{
case 0:
j = cautbin(x);
if(v[j] == x)
out<<j<<'\n';
else
out<<-1<<'\n';
break;
case 1:
j = cautbin(x);
out<<j<<'\n';
break;
case 2:
j = cautbin(x - 1) + 1;
out<<j<<'\n';
break;
}
}
return 0;
}