Pagini recente » Cod sursa (job #2719058) | Cod sursa (job #700573) | Cod sursa (job #2389141) | Cod sursa (job #200987) | Cod sursa (job #2064005)
#include <cstdio>
using namespace std;
int v[100005], n, m, pos;
int funct_0(int x) {
pos = 0;
for (int bit = 1 << 17; bit > 0; bit /= 2)
if (bit + pos <= n && v[bit + pos] <= x)
pos = pos + bit;
if (v[pos] == x)
return pos;
else
return -1; }
int funct_1(int x) {
pos = 0;
for (int bit = 1 << 17; bit > 0; bit /= 2)
if (bit + pos <= n && v[bit + pos] <= x)
pos = pos + bit;
return pos; }
int funct_2(int x) {
pos = 0;
for (int bit = 1 << 17; bit > 0; bit /= 2)
if (bit + pos <= n && v[bit + pos] < x)
pos = pos + bit;
return pos + 1; }
int main() {
freopen("cautbin.in", "r", stdin);
freopen("cautbin.out", "w", stdout);
int c, x;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &v[i]);
scanf("%d", &m);
for (int i = 1; i <= m; i++) {
scanf("%d %d", &c, &x);
if (c == 0)
printf("%d\n", funct_0(x));
if (c == 1)
printf("%d\n", funct_1(x));
if (c == 2)
printf("%d\n", funct_2(x)); }
return 0; }