結果

問題 No.2809 Sort Query
ユーザー cho435
提出日時 2024-07-27 18:03:57
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,483 ms / 2,000 ms
コード長 1,266 bytes
コンパイル時間 5,567 ms
コンパイル使用メモリ 289,020 KB
最終ジャッジ日時 2025-02-23 19:15:31
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 71
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (ll i = s; i < (ll)(t); i++)

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using pbds_tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template<typename T>
bool chmin(T &x, T y) { return x > y ? (x = y, true) : false; }
template<typename T>
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<ll> a(n);
	rep(i,0,n) cin>>a.at(i);
	pbds_tree<pair<ll,ll>> st;
	rep(i,0,n){
		st.insert({0,i});
	}
	map<pair<ll,ll>,pair<ll,ll>> mp;
	rep(i,0,n){
		mp[{0,i}]={a.at(i),i};
	}
	rep(Qi,0,q){
		ll t;
		cin>>t;
		if(t==1){
			ll k,x;
			cin>>k>>x;
			k--;
			auto p=*st.find_by_order(k);
			mp[p]={x,p.second};
		}else if(t==2){
			for(auto[p,q]:mp){
				st.erase(p);
				st.insert(q);
			}
			mp.clear();
		}else if(t==3){
			ll k;
			cin>>k;
			k--;
			auto p=*st.find_by_order(k);
			if(mp.count(p)) p=mp.at(p);
			cout<<p.first<<"\n";
		}
	}
}
0