Pagini recente » Cod sursa (job #1179533) | Cod sursa (job #2482433) | Cod sursa (job #2130992) | Cod sursa (job #234450) | Cod sursa (job #2224852)
#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 == 2)
pos = caut(x - 1) + 1;
ans[++index] = pos;
}
for(int i = 1; i <= m; ++i)
fout << ans[i] << "\n";
return 0;
}