Pagini recente » Cod sursa (job #2151801) | Cod sursa (job #2983127) | Cod sursa (job #706318) | Cod sursa (job #2632962) | Cod sursa (job #1360551)
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
#ifdef HOME
const string inputFile = "input.txt";
const string outputFile = "output.txt";
#else
const string problemName = "cautbin";
const string inputFile = problemName + ".in";
const string outputFile = problemName + ".out";
#endif
const int NMAX = 100000 + 5;
int N, M;
int V[NMAX];
int main() {
int i, j, t, x;
freopen(inputFile.c_str(), "r", stdin);
freopen(outputFile.c_str(), "w", stdout);
scanf("%d", &N);
for(i = 1; i <= N; i++)
scanf("%d", &V[i]);
scanf("%d", &M);
while(M--) {
scanf("%d%d", &t, &x);
i = lower_bound(V + 1, V + N + 1, x) - V;
j = upper_bound(V + 1, V + N + 1, x) - V;
if(t == 0) {
printf("%d\n", (i == j) ? -1 : j - 1);
continue;
}
if(t == 1) {
printf("%d\n", j - 1);
continue;
}
if(t == 2) {
printf("%d\n", i);
continue;
}
}
return 0;
}