func_code_string: #include <bits/stdc++.h>   using namespace std;   int gi() {     char cc = getchar();     int cn = 0, flus = 1;     while (cc <  0  || cc >  9 ) {       if (cc ==  - ) flus = -flus;       cc = getchar();     }     while (cc >=  0  && cc <=  9 ) cn = cn * 10 + cc -  0 , cc = getchar();     return cn * flus;   }   const int N = 1e5 + 5;   int n, m, q, L[N];   struct SegmentBeats {     int bef, mx, se, tot, tag;   } tr[N << 2];   void cmax(int &x, int y) { x = (x < y) ? y : x; }   inline void pushup(int x) {     tr[x].tot = tr[x].se = 0,     tr[x].mx = max(tr[(x << 1)].mx, tr[(x << 1 | 1)].mx);     if (tr[x].mx == tr[(x << 1)].mx)       tr[x].tot += tr[(x << 1)].tot, cmax(tr[x].se, tr[(x << 1)].se);     else       cmax(tr[x].se, tr[(x << 1)].mx);     if (tr[x].mx == tr[(x << 1 | 1)].mx)       tr[x].tot += tr[(x << 1 | 1)].tot, cmax(tr[x].se, tr[(x << 1 | 1)].se);     else       cmax(tr[x].se, tr[(x << 1 | 1)].mx);     tr[x].bef = tr[x].mx;   }   inline void push(int x, int k) { tr[x].mx = k, tr[x].tag = k; }   inline void pushmark(int x) {     if (!tr[x].tag) return;     if (tr[(x << 1)].mx == tr[x].bef) push((x << 1), tr[x].tag);     if (tr[(x << 1 | 1)].mx == tr[x].bef) push((x << 1 | 1), tr[x].tag);     tr[x].tag = 0, tr[x].bef = tr[x].mx;   }   int query(int x, int l, int r, int k) {     if (l == r) return tr[x].mx;     int mid = (l + r) >> 1;     pushmark(x);     if (k <= mid)       return query((x << 1), l, mid, k);     else       return query((x << 1 | 1), mid + 1, r, k);   }   void update(int x, int l, int r, int k, int d) {     if (l == r) return tr[x].mx = d, tr[x].se = 0, tr[x].tot = 1, void();     int mid = (l + r) >> 1;     pushmark(x);     if (k <= mid)       update((x << 1), l, mid, k, d);     else       update((x << 1 | 1), mid + 1, r, k, d);     pushup(x);   }   void modify(int x, int l, int r, int ql, int qr, int y, int z) {     if (tr[x].mx < y || r < ql || qr < l) return;     if ((ql <= l && r <= qr) && (tr[x].se < y && tr[x].mx >= y))       return push(x, z);     int mid = (l + r) >> 1;     pushmark(x);     modify((x << 1), l, mid, ql, qr, y, z),         modify((x << 1 | 1), mid + 1, r, ql, qr, y, z), pushup(x);   }   vector<pair<int, int> > p[N];   int ans[N];   signed main() {     n = gi(), m = gi();     int x, y;     for (int i = (1); i <= (m); ++i) x = gi(), y = gi(), L[y] = x;     q = gi();     for (int i = (1); i <= (q); ++i)       x = gi(), y = gi(), p[y].push_back(make_pair(x, i));     for (int i = (1); i <= (n); ++i) {       update(1, 1, n, i, i);       if (L[i]) modify(1, 1, n, 1, L[i], L[i], i);       for (auto u : p[i]) ans[u.second] = query(1, 1, n, u.first);     }     for (int i = (1); i <= (q); ++i) printf( %d n , ans[i]);     return 0;   }   