Pagini recente » Cod sursa (job #669981) | Cod sursa (job #645114) | Cod sursa (job #163184) | Cod sursa (job #978695) | Cod sursa (job #2062260)
#include <iostream>
using namespace std;
ifstream fin("cautbin.in");
ofstream fout("cautbin.out");
int v[100000], n;
int caut(int x)
{
int r = 0, pas = 1 << 16;
while(pas != 0){
if(r + pas <= n && v[r + pas] <= x) r += pas;
pas >>= 1;
}
return 1 + r;
}
int main()
{
ios_base::sync_with_stdio(false);
int m, a, x, t;
fin >> n;
for(int i = 0 ; i < n ; i++) fin >> v[i];
fin >> m;
for(int i = 0 ; i < m ; i++){
fin >> a >> x;
if(a == 0){
t = caut(x);
fout << (v[t - 1] == x ? t : -1);
}
else if(a == 1) fout << caut(x);
else if(a == 2) fout << caut(x - 1) + 1;
}
return 0;
}