結果

問題 No.2809 Sort Query
ユーザー cho435
提出日時 2024-07-27 18:26:12
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,382 ms / 2,000 ms
コード長 1,392 bytes
コンパイル時間 5,420 ms
コンパイル使用メモリ 283,108 KB
最終ジャッジ日時 2025-02-23 19:17:06
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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({-1,i});
	}
	vector<ll> b=a;
	vector<int> ch(n);
	iota(ch.begin(),ch.end(),0);
	rep(i,0,n) a.at(i)=-1;
	rep(Qi,0,q){
		ll t;
		cin>>t;
		if(t==1){
			ll k,x;
			cin>>k>>x;
			k--;
			auto[p,i]=*st.find_by_order(k);
			if(b.at(i)==-1) ch.push_back(i);
			b.at(i)=x;
		}else if(t==2){
			while(!ch.empty()){
				int i=ch.back();
				ch.pop_back();
				st.erase({a.at(i),i});
				st.insert({b.at(i),i});
				a.at(i)=b.at(i);
				b.at(i)=-1;
			}
		}else if(t==3){
			ll k;
			cin>>k;
			k--;
			auto[p,i]=*st.find_by_order(k);
			if(b.at(i)!=-1) p=b.at(i);
			cout<<p<<"\n";
		}
	}
}
0