#include using namespace std; using ll = long long; template struct dual_segtree { public: dual_segtree() : dual_segtree(0) {} dual_segtree(int n) : dual_segtree(std::vector(n, id())) {} dual_segtree(const std::vector& v) : _n(int(v.size())) { log = ceil_pow2(_n); size = 1 << log; d = std::vector(2 * size, id()); for (int i = 0; i < _n; i++) d[size + i] = v[i]; } const S& operator[](int p) const { assert(0 <= p && p < _n); p += size; for (int i = log; i >= 1; i--) push(p >> i); return d[p]; } S& operator[](int p) { assert(0 <= p && p < _n); p += size; for (int i = log; i >= 1; i--) push(p >> i); return d[p]; } void apply(int p, S f) { assert(0 <= p && p < _n); p += size; for (int i = log; i >= 1; i--) push(p >> i); d[p] = mapping(f, d[p]); } void apply(int l, int r, S f) { assert(0 <= l && l <= r && r <= _n); if (l == r) return; l += size; r += size; for (int i = log; i >= 1; i--) { if (((l >> i) << i) != l) push(l >> i); if (((r >> i) << i) != r) push((r - 1) >> i); } while (l < r) { if (l & 1) all_apply(l++, f); if (r & 1) all_apply(--r, f); l >>= 1; r >>= 1; } } private: int _n, size, log; std::vector d; void all_apply(int k, S f) { d[k] = mapping(f, d[k]); } void push(int k) { all_apply(2 * k, d[k]); all_apply(2 * k + 1, d[k]); d[k] = id(); } int ceil_pow2(int n) { int x = 0; while ((1U << x) < (unsigned int)(n)) x++; return x; } }; int op(int lhs, int rhs){return max(lhs, rhs);} int e(){return -1;} int main(){ ios::sync_with_stdio(false); cin.tie(0); int N, A, T, l, r; cin >> N >> A; vector> a(N); for(int i = 0; i < N; i++){ cin >> a[i].first; a[i].second = i; } sort(a.begin(), a.end()); cin >> T; dual_segtree seg(N); for(int i = 1; i <= T; i++){ cin >> l >> r; l = lower_bound(a.begin(), a.end(), make_pair(l, -1)) - a.begin(); r = lower_bound(a.begin(), a.end(), make_pair(r + 1, -1)) - a.begin(); seg.apply(l, r, i); } vector ans(N); for(int i = 0; i < N; i++) ans[a[i].second] = seg[i]; for(auto v : ans) cout << v << '\n'; }