#include using namespace std; //* ATCODER #include using namespace atcoder; typedef modint998244353 mint; //*/ /* BOOST MULTIPRECISION #include using namespace boost::multiprecision; //*/ typedef long long ll; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) template bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template T max(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]); return ret; } template T min(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]); return ret; } template T sum(vector &a){ T ret = 0; for (int i=0; i<(int)a.size(); i++) ret += a[i]; return ret; } random_device seed_gen; mt19937 engine(seed_gen()); uniform_int_distribution dist_treap(0, (1 << 30) - 1); struct treap { struct node { node *lch, *rch; int par; ll val; int cnt; node(ll v, int p): lch(nullptr), rch(nullptr), par(p), val(v), cnt(1) {} }; int calc_cnt(node* t){ if (t == nullptr) return 0; return t->cnt; } node* update(node* t){ t->cnt = calc_cnt(t->lch) + calc_cnt(t->rch) + 1; return t; } node* merge(node* a, node* b){ if (a == nullptr || b == nullptr){ if (a == nullptr) return b; return a; } if (a->par > b->par){ a->rch = merge(a->rch, b); return update(a); }else{ b->lch = merge(a, b->lch); return update(b); } } pair split(node* t, int k){ if (t == nullptr) return pair(nullptr, nullptr); assert(0 <= k && k <= calc_cnt(t)); if (calc_cnt(t->lch) >= k){ pair ret = split(t->lch, k); t->lch = ret.second; return pair(ret.first, update(t)); }else{ pair ret = split(t->rch, k - calc_cnt(t->lch) - 1); t->rch = ret.first; return pair(update(t), ret.second); } } node* insert(node* t, int k, ll v){ return insert(t, k, v, dist_treap(engine)); } node* insert(node* t, int k, ll v, int p){ pair tar = split(t, k); node* var = new node(v, p); return merge(merge(tar.first, var), tar.second); } node* erase(node* t, int k){ assert(0 <= k && k < calc_cnt(t)); pair spl1 = split(t, k + 1); pair spl2 = split(spl1.first, k); delete spl2.second; return merge(spl2.first, spl1.second); } // returns the number of elements less than v int lower_bound(node* t, ll v){ if (t == nullptr) return 0; if (v <= t->val){ return lower_bound(t->lch, v); }else{ return calc_cnt(t->lch) + 1 + lower_bound(t->rch, v); } } node* insert(node* t, ll v){ return insert(t, lower_bound(t, v), v); } // returns val ll get(node* t, int k){ assert(t != nullptr); if (k < calc_cnt(t->lch)){ return get(t->lch, k); }else if(calc_cnt(t->lch) == k){ return t->val; }else{ return get(t->rch, k - calc_cnt(t->lch) - 1); } } ll change(node* t, int k, ll x){ assert(t != nullptr); if (k < calc_cnt(t->lch)){ return change(t->lch, k, x); }else if(calc_cnt(t->lch) == k){ t->val = x; return t->val; }else{ return change(t->rch, k - calc_cnt(t->lch) - 1, x); } } }; int main(){ int n, q; cin >> n >> q; vector a(n); rep(i,0,n){ cin >> a[i]; } set changes; rep(i,0,n){ changes.insert(i); } treap T; treap::node* root = nullptr; rep(i,0,n){ root = T.insert(root, i, a[i]); } while(q--){ int t; cin >> t; if (t == 1){ int k; cin >> k; k--; ll x; cin >> x; changes.insert(k); T.change(root, k, x); }else if(t == 2){ vector vals; int piv = 0; for(int i: changes){ vals.push_back(T.get(root, i-piv)); root = T.erase(root, i-piv); piv++; } for(ll x: vals){ root = T.insert(root, x); } changes.clear(); }else{ int k; cin >> k; k--; cout << T.get(root, k) << '\n'; } } }