func_code_string: #include <bits/stdc++.h>   using namespace std;   set<pair<long long, long long> > s1;   long long a[212345], ans[212345];   long long b[212345];   signed main() {     std::ios::sync_with_stdio(false);     long long n, m;     cin >> n >> m;     for (long long i = 1; i <= n; i++) cin >> a[i];     for (long long i = 1; i <= m; i++) {       long long b2;       cin >> b[i] >> b2;       pair<long long, long long> now = make_pair(b2, i);       s1.insert(now);       while (*s1.begin() != now) s1.erase(s1.begin());     }     s1.insert(make_pair(0, 0));     set<pair<long long, long long> >::iterator t = s1.end();     t--;     for (long long i = (*t).first + 1; i <= n; i++) ans[i] = a[i];     sort(a + 1, a + (*t).first + 1);     long long l = 0, r = (*t).first + 1;     while (t != s1.begin()) {       set<pair<long long, long long> >::iterator tl = t;       tl--;       for (long long i = (*t).first; i > (*tl).first; i--) {         if (b[(*t).second] == 1)           ans[i] = a[--r];         else           ans[i] = a[++l];       }       t--;     }     for (long long i = 1; i <= n; i++) cout << ans[i] <<    ;     cout <<   n ;     return 0;   }   