#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({-1,i}); } vector b=a; vector ch(n); iota(ch.begin(),ch.end(),0); rep(i,0,n) a.at(i)=-1; rep(Qi,0,q){ ll t; cin>>t; if(t==1){ ll k,x; cin>>k>>x; k--; auto[p,i]=*st.find_by_order(k); if(b.at(i)==-1) ch.push_back(i); b.at(i)=x; }else if(t==2){ while(!ch.empty()){ int i=ch.back(); ch.pop_back(); st.erase({a.at(i),i}); st.insert({b.at(i),i}); a.at(i)=b.at(i); b.at(i)=-1; } }else if(t==3){ ll k; cin>>k; k--; auto[p,i]=*st.find_by_order(k); if(b.at(i)!=-1) p=b.at(i); cout<