Pagini recente » Cod sursa (job #315430) | Cod sursa (job #2833960) | Cod sursa (job #1889049) | Cod sursa (job #1032615) | Cod sursa (job #3288529)
#include <bits/stdc++.h>
using namespace std;
ifstream f("cautbin.in");
ofstream o("cautbin.out");
int main()
{
int N, M, x, acc = 0, curent_pow_2 = 16, v[100001], caz;
f >> N;
for (int i = 1; i <= N; i++)
{
f >> v[i];
}
f >> M;
for (int i = 0; i < M; i++)
{
cout << 1;
f >> caz >> x;
curent_pow_2 = 16;
acc = 0;
while (curent_pow_2 > 0)
{
if (acc + curent_pow_2 <= N)
if (v[acc + curent_pow_2] <= x)
acc += curent_pow_2;
curent_pow_2 >>= 1;
}
if (caz == 2)
{
acc++;
cout << acc;
}
if (caz == 0)
{
if (v[acc] == x)
o << acc << endl;
else
{
cout << -1 << endl;
}
}
if (caz == 1)
cout<< acc << endl;
}
return 0;
}