Pagini recente » Cod sursa (job #3360830) | Cod sursa (job #3360628) | Cod sursa (job #3360829) | Cod sursa (job #3360718)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("cautbin.in");
ofstream fout ("cautbin.out");
const int MAXN = 100000;
int n;
int v[MAXN + 1];
int c0(int x) {
int st, dr, mij;
st = 1;
dr = n + 1;
while (dr - st > 1) {
mij = st + (dr - st) / 2;
if (v[mij] <= x)
st = mij;
else
dr = mij;
}
return (v[st] == x ? st : -1);
}
int c1(int x) {
int st, dr, mij;
st = 1;
dr = n + 1;
while (dr - st > 1) {
mij = st + (dr - st) / 2;
if (v[mij] <= x)
st = mij;
else
dr = mij;
}
return st;
}
int c2(int x) {
int st, dr, mij;
st = 0;
dr = n;
while (dr - st > 1) {
mij = st + (dr - st) / 2;
if (v[mij] < x)
st = mij;
else
dr = mij;
}
return dr;
}
int main() {
int m, c, x;
fin >> n;
for (int i = 1; i <= n; i++)
fin >> v[i];
fin >> m;
for (int i = 1; i <= m; i++) {
fin >> c >> x;
if (c == 0)
fout << c0 (x) << '\n';
else if (c == 1)
fout << c1 (x) << '\n';
else if (c == 2)
fout << c2 (x) << '\n';
}
return 0;
}