#include #include using namespace std; using ll = long long; #define rep(i, s, t) for (ll i = s; i < (ll)(t); i++) #include #include using namespace __gnu_pbds; template using pbds_tree = tree, rb_tree_tag, tree_order_statistics_node_update>; template bool chmin(T &x, T y) { return x > y ? (x = y, true) : false; } template bool chmax(T &x, T y) { return x < y ? (x = y, true) : false; } struct io_setup { io_setup() { ios::sync_with_stdio(false); std::cin.tie(nullptr); cout << fixed << setprecision(15); } } io_setup; int main(){ ll n,q; cin>>n>>q; vector a(n); rep(i,0,n) cin>>a.at(i); pbds_tree> st; rep(i,0,n){ st.insert({0,i}); } map,pair> mp; rep(i,0,n){ mp[{0,i}]={a.at(i),i}; } rep(Qi,0,q){ ll t; cin>>t; if(t==1){ ll k,x; cin>>k>>x; k--; auto p=*st.find_by_order(k); mp[p]={x,p.second}; }else if(t==2){ for(auto[p,q]:mp){ st.erase(p); st.insert(q); } mp.clear(); }else if(t==3){ ll k; cin>>k; k--; auto p=*st.find_by_order(k); if(mp.count(p)) p=mp.at(p); cout<