#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using namespace atcoder; using namespace __gnu_pbds; using mint = modint1000000007; #define rep(i,n) for (int i=0;i-1;i--) #define pb push_back #define all(x) (x).begin(), (x).end() #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << " )\n"; template using vec = vector; template using vvec = vec>; template using vvvec = vec>; using ll = long long; using pii = pair; using pll = pair; template bool chmin(T &a, T b){ if (a>b){ a = b; return true; } return false; } template bool chmax(T &a, T b){ if (a T sum(vec x){ T res=0; for (auto e:x){ res += e; } return res; } template void printv(vec x){ for (auto e:x){ cout< ostream& operator<<(ostream& os, const pair& A){ os << "(" << A.first <<", " << A.second << ")"; return os; } template ostream& operator<<(ostream& os, const set& S){ os << "set{"; for (auto a:S){ os << a; auto it = S.find(a); it++; if (it!=S.end()){ os << ", "; } } os << "}"; return os; } template ostream& operator<<(ostream& os, const tuple& a){ auto [x,y,z] = a; os << "(" << x << ", " << y << ", " << z << ")"; return os; } template ostream& operator<<(ostream& os, const map& A){ os << "map{"; for (auto e:A){ os << e.first; os << ":"; os << e.second; os << ", "; } os << "}"; return os; } template ostream& operator<<(ostream& os, const vec& A){ os << "["; rep(i,A.size()){ os << A[i]; if (i!=A.size()-1){ os << ", "; } } os << "]" ; return os; } ostream& operator<<(ostream& os, const mint& a){ os << a.val(); return os; } void solve(){ int N,Q; cin>>N>>Q; vec A(N); rep(i,N) cin>>A[i]; tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> sorted_val_set; set update_idx = {}; rep(i,N){ update_idx.insert(i); } map update_val; rep(i,N){ update_val[i] = A[i]; } rep(i,N){ sorted_val_set.insert({ll(i),ll(i)}); } int nxt = N; while (Q--){ int t; cin>>t; if (t == 1){ int k;ll x; cin>>k>>x; k--; if (!update_idx.count(k)){ update_idx.insert(k); } update_val[k] = x; } else if (t == 2){ int tmp = 0; //debug(update_idx); //assert (sorted_val_set.size() == N); for (auto i:update_idx){ auto [val,x] = *sorted_val_set.find_by_order(i-tmp); //debug(make_pair(val,x)); sorted_val_set.erase({val,x}); tmp++; //sorted_val_set.insert({update_val[i],i}); //for (auto [a,b]:sorted_val_set){ //cout << a << " " << b << "\n"; //} } for (auto i:update_idx){ sorted_val_set.insert({update_val[i],ll(nxt)}); nxt++; } update_idx.clear(); update_val.clear(); } else{ int k; cin>>k; k--; if (!update_idx.count(k)){ auto [val,x] = *sorted_val_set.find_by_order(k); cout << val << "\n"; } else{ cout << update_val[k] << "\n"; } } } } int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); cout << fixed << setprecision(15); int T = 1; while (T--){ solve(); } }