#include #include using namespace std; using namespace atcoder; //using mint = modint1000000007; //const int mod = 1000000007; //using mint = modint998244353; //const int mod = 998244353; //const int INF = 1e9; //const long long LINF = 1e18; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n) - 1; i >= 0; --i) #define rrep2(i,l,r)for(int i=(r) - 1;i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define P pair template inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, q; cin >> n >> q; vectora(n); rep(i, n)cin >> a[i]; struct Query { int t; int k; long long x; Query(int t = -1, int k = -1, long long x = -1) :t(t), k(k), x(x) {} void output() { std::cout << t << " " << k << " " << x << endl; } }; vectorcomp = a; vectorquery(q); rep(i, q) { cin >> query[i].t; if (3 == query[i].t) cin >> query[i].k; else if (1 == query[i].t) { cin >> query[i].k >> query[i].x; comp.push_back(query[i].x); } } sort(all(comp)); comp.erase(unique(all(comp)), comp.end()); fenwick_tree bit(comp.size()); rep(i, q) { if (1 == query[i].t) { query[i].x = lower_bound(all(comp), query[i].x) - comp.begin(); } } vectorchange(n, -1); vector>chq; vectorupd; rep(i, n) { a[i] = lower_bound(all(comp), a[i]) - comp.begin(); change[i] = a[i]; upd.push_back(i); } bit.add(0, n); auto f = [&](int x)->int { int ok = 0; int ng = comp.size(); while (abs(ok - ng) > 1) { int mid = (ok + ng) / 2; bool chk = bit.sum(0, mid) <= x; if (chk)ok = mid; else ng = mid; } return ok; }; rep(i, q) { int t = query[i].t; int k = query[i].k; int x = query[i].x; if (1 == t) { change[k - 1] = x; upd.push_back(k - 1); } else if (2 == t) { while (!upd.empty()) { if (-1 != change[upd.back()]) { int pos = f(upd.back()); chq.push_back({ pos,change[upd.back()] }); change[upd.back()] = -1; } upd.pop_back(); } while (!chq.empty()) { auto[f, s] = chq.back(); bit.add(f, -1); bit.add(s, 1); chq.pop_back(); } } else { if (-1 != change[k - 1]) { cout << comp[change[k - 1]] << endl; } else { cout << comp[f(k - 1)] << endl; } } } return 0; }