Pagini recente » Cod sursa (job #2641892) | Cod sursa (job #685935) | Cod sursa (job #348137) | Cod sursa (job #2343595) | Cod sursa (job #1290398)
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
#define dbg(x) (cout<<#x<<" = "<<(x)<<'\n')
#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 // HOME
typedef long long int lld;
typedef pair<int, int> PII;
typedef pair<int, lld> PIL;
typedef pair<lld, int> PLI;
typedef pair<lld, lld> PLL;
const int INF = (1LL << 31) - 1;
const lld LINF = (1LL << 62) - 1;
const int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};
const int MOD = (int)(1e9) + 7;
const int NMAX = 100000 + 5;
const int MMAX = 100000 + 5;
const int KMAX = 100000 + 5;
const int PMAX = 100000 + 5;
const int LMAX = 100000 + 5;
const int VMAX = 100000 + 5;
int N, M;
int V[NMAX];
int main() {
int i, t, x;
#ifndef ONLINE_JUDGE
freopen(inputFile.c_str(), "r", stdin);
freopen(outputFile.c_str(), "w", stdout);
#endif
scanf("%d", &N);
for(i = 1; i <= N; i++)
scanf("%d", &V[i]);
scanf("%d", &M);
while(M--) {
scanf("%d%d", &t, &x);
if(t == 0) {
auto it = upper_bound(V + 1, V + N + 1, x);
it--;
printf("%d\n", *it == x ? (it - V) : -1);
} else if(t == 1) {
auto it = upper_bound(V + 1, V + N + 1, x);
it--;
printf("%d\n", (it - V));
} else {
auto it = lower_bound(V + 1, V + N + 1, x);
printf("%d\n", (it - V));
}
}
return 0;
}