Pagini recente » Cod sursa (job #1601504) | Profil stay_awake77 | Cod sursa (job #2514928) | Cod sursa (job #2506774) | Cod sursa (job #1755055)
#include <fstream>
using namespace std;
ifstream f ("cautbin.in");
ofstream g ("cautbin.out");
int N, x, step, i, a[1000], P, K;
int main()
{
f >> N;
for(i = 1; i <= N; i++) f >> a[i];
f >> K;
for(int ic = 1; ic <= K; ic++) {
f >> P >> x;
for(step = 1; step < N; step <<= 1);
step >>= 1;
for(i = 0; step; step >>= 1) {
if(i + step <= N && a[i + step] <= x) i += step;
}
if(P == 1) g << i << "\n";
if(P == 2) {
while(a[i] == x) i--;
i++;
g << i << "\n";
}
if(P == 0) {
while(a[i] == x) i++;
i--;
if(a[i] == x) g << i << "\n";
else g << -1 << "\n";
}
}
return 0;
}