結果

問題 No.2809 Sort Query
ユーザー highlighter
提出日時 2024-04-23 00:25:58
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,272 bytes
コンパイル時間 6,247 ms
コンパイル使用メモリ 338,064 KB
実行使用メモリ 30,876 KB
最終ジャッジ日時 2024-07-12 21:00:45
合計ジャッジ時間 15,826 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 1 TLE * 1 -- * 69
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/extc++.h>
using namespace std;
using namespace __gnu_cxx;

int lower_bound(rope<long long> v,long long k){
	int N=(int)(v.size());
	if(N==0){
		return 0;
	}
	//k<=v[i]であるような最小のi
	//存在しない場合はNを返す
	//O(|v|log^2|v|)
	if(v[N-1]<k){
		return N;
	}
	if(k<=v[0]){
		return 0;
	}
	int l=0;
	int r=N-1;
	while((r-l)>1){
		int m=(l+r)/2;
		if(k<=v[m]){
			r=m;
			continue;
		}
		l=m;
	}
	return r;
}

int main(){
	int N,Q;
	scanf("%d%d",&N,&Q);
	rope<long long> A;
	for(int i=0;i<N;i++){
		long long x;
		scanf("%lld",&x);
		A.push_back(x);
	}
	set<int,greater<int>> B;//indexを保存
	queue<long long> C;//valueを保存
	for(int i=0;i<N;i++){
		B.insert(i);
	}
	for(;Q--;){
		int c;
		scanf("%d",&c);
		if(c==1){
			int k;
			long long x;
			scanf("%d%lld",&k,&x);
			k--;
			A.erase(k,1);
			A.insert(k,x);
			B.insert(k);
			continue;
		}
		if(c==2){
			if(B.size()==0){
				continue;
			}
			for(int i : B){
				C.push(A[i]);
				A.erase(i,1);
			}
			B.clear();
			while(!C.empty()){
				long long pos=C.front();
				C.pop();
				int t=lower_bound(A.begin(),A.end(),pos)-A.begin();
				A.insert(t,pos);
			}
			continue;
		}
		if(c==3){
			int k;
			scanf("%d",&k);
			k--;
			printf("%lld\n",A[k]);
			continue;
		}
	}
}
0