#include using namespace std; #define rep(i, n) for(int i=0; i #include struct SegTree { int n = 1; vector tree; SegTree(int N) { while (n < N) { n *= 2; } vector v(n * 2, -1); swap(v, tree); } void Update(int l, int r, int t, int b, int u, int now) { if (r <= b || l>=u) { return; } else if (l <= b && r >= u) { tree[now] = t; return; } else { Update(l, r, t, b, (b + u) / 2, now * 2 + 1); Update(l, r, t, (b + u) / 2, u, now * 2 + 2); } } void Query(int L, int R, int t) { Update(L, R + 1, t, 0, n, 0); } int Calc(int now, int x) { if (now == 0) { return x; } else { return Calc((now - 1) / 2, max(x, tree[now])); } } int Ans(int i) { return Calc(n - 1 + i, -1); } }; int main() { int N, A; cin >> N >> A; vector X(N); rep(i, N) { cin >> X[i]; } int T; cin >> T; vector> query(T, vector(2)); rep(i, T) { cin >> query[i][0] >> query[i][1]; } set s; rep(i, N) { s.insert(X[i]); } rep(i, T) { s.insert(query[i][0]); s.insert(query[i][1]); } vector x(N); vector> q(T, vector(2)); map mp; int c = 0; for (int t : s) { mp[t] = c; c++; } rep(i, N) { x[i] = mp[X[i]]; } rep(i, T) { q[i] = { mp[query[i][0]], mp[query[i][1]] }; } SegTree st(c); rep(i, T) { st.Query(q[i][0], q[i][1], i + 1); } rep(i, N) { cout << st.Ans(x[i]) << endl; } }