#include using namespace std; using ll = long long; #ifdef LOCAL #include #else #define debug(...) #endif #include #include using namespace __gnu_pbds; using k_set = tree, rb_tree_tag, tree_order_statistics_node_update>; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); int N, Q; cin >> N >> Q; vector A(N); for (int i = 0; i < N; i++) cin >> A[i]; k_set not_sort; for (int i = 0; i < N; i++) not_sort.insert(i); k_set st; while (Q--) { int type; cin >> type; if (type == 1) { int k, x; cin >> k >> x, k--; st.erase(A[k]); A[k] = x; not_sort.insert(k); } if (type == 2) { // sort for (int i : not_sort) st.insert(A[i]); not_sort.clear(); } if (type == 3) { int k; cin >> k, k--; if (not_sort.find(k) != not_sort.end()) { cout << A[k] << '\n'; } else { // [0, k) にあるソートされていない要素数 int cnt = not_sort.order_of_key(k); cout << *st.find_by_order(k - cnt) << '\n'; } } } }