#include using namespace std; int main() { int n,a; cin >> n >> a; vector X(n); for (auto& x: X) cin >> x; int t; cin >> t; vector L(n),R(n); for (int i = 0; i < t; i++){ cin >> L[i] >> R[i]; } vector> event; vector used(n+1,0); vector ans(n,-1); priority_queue> h; for (int i = 0; i < n; i++){ event.push_back({X[i],0,i}); } for (int i = 0; i < t; i++){ event.push_back({L[i],-1,i}); event.push_back({R[i],1,i}); } sort(event.begin(),event.end()); for (auto [t,f,ind] : event){ if (f == 0){ while (!h.empty()){ auto [t,ind] = h.top(); if (used[ind]) h.pop(); else break; } if (!h.empty()){ ans[ind] = h.top().first; } } if (f == -1){ h.push({ind+1,ind}); } if (f == 1){ used[ind] = 1; } } for (auto a: ans){ cout << a << endl; } return 0; }