#include using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) using ll = long long; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr double EPS = 1e-8; constexpr int MOD = 998244353; // constexpr int MOD = 1000000007; constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1}; constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1}; constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1}; template inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; } template inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << fixed << setprecision(20); } } iosetup; int main() { int n, a; cin >> n >> a; vector x(n); for (int& x_i : x) cin >> x_i; int t; cin >> t; vector l(t), r(t); REP(i, t) cin >> l[i] >> r[i]; vector pts; pts.reserve(n + 2 * t); ranges::copy(x, back_inserter(pts)); ranges::copy(l, back_inserter(pts)); ranges::copy(r, back_inserter(pts)); ranges::sort(pts); pts.erase(unique(pts.begin(), pts.end()), pts.end()); const int m = pts.size(); REP(i, n) x[i] = distance(pts.begin(), ranges::lower_bound(pts, x[i])); REP(i, t) l[i] = distance(pts.begin(), ranges::lower_bound(pts, l[i])); REP(i, t) r[i] = distance(pts.begin(), ranges::lower_bound(pts, r[i])); vector> ins(m), era(m), queries(m); REP(i, n) ins[l[i]].emplace_back(i); REP(i, n) era[r[i]].emplace_back(i); REP(i, t) queries[x[i]].emplace_back(i); vector ans(n, -1); set sounds; REP(i, m) { for (const int id : ins[i]) sounds.emplace(id); if (!sounds.empty()) { for (const int id : queries[i]) ans[id] = *sounds.rbegin() + 1; } for (const int id : era[i]) sounds.erase(id); } for (const int ans_i : ans) cout << ans_i << '\n'; return 0; }