Pagini recente » Cod sursa (job #1720354) | Cod sursa (job #192751) | Cod sursa (job #472264) | Cod sursa (job #945836) | Cod sursa (job #818632)
Cod sursa(job #818632)
int main()
{
freopen("cautbin.in", "r", stdin);
freopen("cautbin.out", "w", stdout);
{
int num_elem, *Array, num_tests;
scanf ("%d", &num_elem);
Array = new int[N];
for (int i = 0; i < num_elem; i++)
scanf ("%d", &Array[i]);
scanf ("%d", &num_tests);
for (int j = 0; j < num_tests; j++) {
int type, elem;
scanf ("%d %d", &type, &elem);
int i, binary_step;
for (binary_step = 1; binary_step <= num_elem; binary_step <<=1);
for (i = -1; binary_step; binary_step >>= 1)
if (i + binary_step < num_elem &&
(type < 2 && V[i + binary_step] <= elem ||
type == 2 && V[i + binary_step] < elem))
i += binary_step;
int res;
switch (type) {
case 0:
res = i == -1 || V[i] != elem ? -1 : i;
break;
case 1:
case 2:
res = i;
break;
}
printf ("%d\n", res);
}
}
return 0;
}