#pragma GCC optimize("Ofast") #include using namespace std; #include #include using namespace __gnu_pbds; struct segtree{ int n; vector dat; segtree(int _n):n(_n){ dat.resize(2*n); } void update(int i, int c){ i += n; dat[i] = c; i /= 2; while(i){ dat[i] = dat[2*i] + dat[2*i+1]; i /= 2; } } int sum(int l, int r){ l += n; r += n; int ret = 0; while(l < r){ if(l & 1) ret += dat[l++]; if(r & 1) ret += dat[--r]; l /= 2, r /= 2; } return ret; } }; int main(){ int n, q; scanf("%d%d", &n, &q); assert(1 <= n && n <= 500000 && 1 <= q && q <= 500000); tree, rb_tree_tag, tree_order_statistics_node_update> m; segtree ch(n); unordered_map m2; long long check_x = 0; for(int i = 0; i < n; i++){ long long x; scanf("%ld", &x); assert(1 <= x && x <= 1000000000000000000LL); assert(check_x <= x); check_x = x; m.insert(x); } while(q--){ int type; scanf("%d", &type); assert(1 <= type && type <= 3); if(type == 1){ int k; long long x; scanf("%d%ld", &k, &x); assert(1 <= k && k <= n && 1 <= x && x <= 1000000000000000000LL); k--; if(m2.count(k)){ m2[k] = x; }else{ m2[k] = x; ch.update(k, 1); int c = ch.sum(0, k); auto p = m.find_by_order(k - c); m.erase(p); } }else if(type == 2){ for(auto [p, q] : m2){ ch.update(p, 0); m.insert(q); } m2.clear(); }else{ int k; scanf("%d", &k); assert(1 <= k && k <= n); k--; if(m2.count(k)){ printf("%ld\n", m2[k]); }else{ int c = ch.sum(0, k); auto p = m.find_by_order(k - c); printf("%ld\n", *p); } } } }