#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; } template std::pair, int> compression(std::vectororg) { auto copy = org; std::sort(copy.begin(), copy.end()); copy.erase(unique(copy.begin(), copy.end()), copy.end()); for (auto &e : org) { e = std::lower_bound(copy.begin(), copy.end(), e) - copy.begin(); } return { org,copy.size() }; } int op(int a, int b) { return a + b; } int e() { return 0; } int target; bool f(int v) { return v <= target; } 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; } }; vectornums; vectorquery(q); rep(i, q) { int t, k; long long x; cin >> t; if (1 == t) { cin >> k >> x, k--; nums.push_back(x); } else if (3 == t) { cin >> k, k--; } query[i] = Query(t, k, x); } int i = 0; for (; i < q;) { while (i < q && 2 != query[i].t) { if (3 == query[i].t) cout << a[query[i].k] << endl; else a[query[i].k] = query[i].x; i++; } break; } i++; rep(i, n) nums.push_back(a[i]); auto[comp, sz] = compression(nums); mapinv; maptrans; rep(i, nums.size()) { trans[nums[i]] = comp[i]; inv[comp[i]] = nums[i]; } segtreeseg(sz); rep(i, n) { auto get = seg.get(trans[a[i]]); //cout << a[i] << " " << trans[a[i]] << " " << get << endl; seg.set(trans[a[i]], get + 1); } //rep(i, sz) { // cout << seg.get(i) << " "; //}cout << endl; for (; i < q;) { mapmp;//index,compValue while (i < q && 2 != query[i].t) { int index = query[i].k; if (3 == query[i].t) { if (mp.count(index)) { auto ans = mp[index]; ans = inv[ans]; cout << ans << endl; } else { target = index; auto pos = seg.max_right(0); auto ans = inv[pos]; cout << ans << endl; } } else { mp[index] = trans[query[i].x]; } i++; } vector>vec; for (auto[k, v] : mp) { target = k; auto index = seg.max_right(0); vec.push_back({ index ,v }); } for (auto p : vec) { { auto get = seg.get(p.first); seg.set(p.first, get - 1); } { auto get = seg.get(p.second); seg.set(p.second, get + 1); } } } return 0; }