Pagini recente » Cod sursa (job #2073448) | Cod sursa (job #2002666) | Cod sursa (job #638525) | Cod sursa (job #1649061) | Cod sursa (job #2224853)
#include <iostream>
#include <fstream>
using namespace std;
const int MAXN = 100005;
int num[MAXN], ans[MAXN];
int n;
int caut(int x){
int rez = 0, pas = 1 << 20;
while(pas){
if(rez + pas <= n && num[rez + pas] <= x)
rez += pas;
pas /= 2;
}
return rez;
}
int main()
{
ifstream fin("cautbin.in");
ofstream fout("cautbin.out");
fin >> n;
for(int i = 1; i <= n; ++i)
fin >> num[i];
int m, op, x;
fin >> m;
int index = 0;
for(int q = 1; q <= m; ++q){
fin >> op >> x;
int pos = caut(x);
if(op == 0 && num[pos] != x)
pos = -1;
if(op == 2)
pos = caut(x - 1) + 1;
ans[++index] = pos;
}
for(int i = 1; i <= m; ++i)
fout << ans[i] << "\n";
return 0;
}