func_code_string: #include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const long long LINF = 1e18;   const int MOD = 1e9 + 7;   void test() {}   const int MAX = 1 << 19;   int tree[2 * MAX], prefMax[2 * MAX];   int killed = 0, m, n;   vector<pair<int, int> > play;   int query(int x, int y) {     int res = -1;     for (x += MAX, y += MAX; x < y; x >>= 1, y >>= 1) {       if (x & 1) res = max(tree[x++], res);       if (y & 1) res = max(tree[--y], res);     }     return res;   }   void update1(int x) {     x += MAX;     while (x) {       tree[x] = 0;       x /= 2;     }   }   void update2(int x, int val) {     x += MAX;     while (x) {       tree[x] = max(tree[x], val);       x /= 2;     }   }   bool check(int x) {     int l = -1, r = m;     int maks = query(killed, killed + x + 1);     while (l + 1 < r) {       int mid = (l + r) / 2;       if (play[mid].first >= maks)         r = mid;       else         l = mid;     }     if (r == m) return false;     if (prefMax[r] > x)       return true;     else       return false;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       cin >> n;       for (int i = 0; i <= n; i++) update1(i);       for (int i = 0; i < n; i++) {         int x;         cin >> x;         update2(i, x);       }       cin >> m;       play = vector<pair<int, int> >(m);       for (int i = 0; i < m; i++) cin >> play[i].first >> play[i].second;       sort(play.begin(), play.end());       for (int i = m; i >= 0; i--) prefMax[i] = 0;       for (int i = m - 1; i >= 0; i--)         prefMax[i] = max(prefMax[i + 1], play[i].second);       killed = 0;       int res = 0;       bool czy = true;       while (killed < n) {         int l = -1, r = n - killed + 1;         while (l + 1 < r) {           int mid = (l + r) / 2;           if (check(mid))             l = mid;           else             r = mid;         }         if (l == -1) {           cout << -1 <<   n ;           czy = false;           break;         }         killed += (l + 1);         res++;       }       if (czy) cout << res <<   n ;     }   }   