結果

問題 No.2809 Sort Query
ユーザー highlighterhighlighter
提出日時 2024-06-12 20:24:00
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 471 ms / 2,000 ms
コード長 2,370 bytes
コンパイル時間 3,796 ms
コンパイル使用メモリ 265,888 KB
実行使用メモリ 41,068 KB
最終ジャッジ日時 2024-07-12 21:06:29
合計ジャッジ時間 37,395 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 363 ms
36,072 KB
testcase_02 AC 366 ms
36,712 KB
testcase_03 AC 363 ms
35,640 KB
testcase_04 AC 370 ms
35,608 KB
testcase_05 AC 367 ms
35,568 KB
testcase_06 AC 271 ms
32,200 KB
testcase_07 AC 272 ms
32,000 KB
testcase_08 AC 271 ms
32,664 KB
testcase_09 AC 273 ms
32,304 KB
testcase_10 AC 270 ms
32,048 KB
testcase_11 AC 267 ms
33,948 KB
testcase_12 AC 259 ms
34,036 KB
testcase_13 AC 266 ms
33,932 KB
testcase_14 AC 266 ms
33,952 KB
testcase_15 AC 270 ms
34,040 KB
testcase_16 AC 267 ms
34,024 KB
testcase_17 AC 265 ms
33,936 KB
testcase_18 AC 264 ms
34,008 KB
testcase_19 AC 268 ms
33,932 KB
testcase_20 AC 264 ms
34,004 KB
testcase_21 AC 459 ms
41,032 KB
testcase_22 AC 455 ms
40,976 KB
testcase_23 AC 471 ms
40,956 KB
testcase_24 AC 462 ms
41,068 KB
testcase_25 AC 459 ms
41,024 KB
testcase_26 AC 440 ms
36,900 KB
testcase_27 AC 434 ms
36,976 KB
testcase_28 AC 434 ms
37,404 KB
testcase_29 AC 431 ms
36,876 KB
testcase_30 AC 435 ms
37,020 KB
testcase_31 AC 229 ms
31,768 KB
testcase_32 AC 229 ms
31,684 KB
testcase_33 AC 227 ms
31,672 KB
testcase_34 AC 226 ms
31,620 KB
testcase_35 AC 229 ms
31,620 KB
testcase_36 AC 227 ms
33,968 KB
testcase_37 AC 225 ms
34,020 KB
testcase_38 AC 230 ms
33,956 KB
testcase_39 AC 228 ms
34,036 KB
testcase_40 AC 255 ms
34,028 KB
testcase_41 AC 439 ms
32,784 KB
testcase_42 AC 444 ms
32,776 KB
testcase_43 AC 451 ms
32,784 KB
testcase_44 AC 421 ms
32,836 KB
testcase_45 AC 418 ms
32,812 KB
testcase_46 AC 362 ms
32,784 KB
testcase_47 AC 359 ms
32,876 KB
testcase_48 AC 366 ms
32,812 KB
testcase_49 AC 357 ms
32,840 KB
testcase_50 AC 362 ms
32,860 KB
testcase_51 AC 392 ms
32,892 KB
testcase_52 AC 401 ms
32,812 KB
testcase_53 AC 317 ms
32,780 KB
testcase_54 AC 334 ms
32,840 KB
testcase_55 AC 257 ms
32,848 KB
testcase_56 AC 274 ms
27,752 KB
testcase_57 AC 223 ms
24,196 KB
testcase_58 AC 211 ms
22,180 KB
testcase_59 AC 234 ms
25,828 KB
testcase_60 AC 265 ms
22,216 KB
testcase_61 AC 320 ms
28,252 KB
testcase_62 AC 218 ms
23,392 KB
testcase_63 AC 303 ms
28,288 KB
testcase_64 AC 368 ms
32,228 KB
testcase_65 AC 201 ms
19,580 KB
testcase_66 AC 2 ms
6,940 KB
testcase_67 AC 2 ms
6,940 KB
testcase_68 AC 2 ms
6,944 KB
testcase_69 AC 2 ms
6,944 KB
testcase_70 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

struct Fenwick_tree{
	private:
	unsigned int siz=1;
	vector<int> dat;
	public:
	Fenwick_tree(int N) : dat(N,0){
		siz=N;
	}
	void add(int k,int x){
		for(int i=k;i<siz;i+=((i+1)&(-i-1))){
			dat[i]+=x;
		}
	}
	int max_right(int x){
		int ans=0;
		int res=0;
		int h=bit_floor(siz-1);
		while(h>0){
			if(ans+h<=siz){
				if(res+dat[ans+h-1]<=x){
					res+=dat[ans+h-1];
					ans+=h;
				}
			}
			h/=2;
		}
		return ans;
	}
};

signed main(){
	int N,Q;
	scanf("%d%d",&N,&Q);
	vector<long long> A(N);
	for(int i=0;i<N;i++){
		scanf("%lld",&A[i]);
	}
	vector<long long> data=A;
	vector<vector<long long>> query(Q);
	for(int i=0;i<Q;i++){
		int c;
		scanf("%d",&c);
		if(c==1){
			int k;
			long long x;
			scanf("%d%lld",&k,&x);
			data.emplace_back(x);
			query[i]={c,k,x};
			continue;
		}
		if(c==2){
			query[i]={c};
			continue;
		}
		int k;
		scanf("%d",&k);
		query[i]={c,k};
	}
	vector<long long> data2=data;
	sort(data2.begin(),data2.end());
	data2.erase(unique(data2.begin(),data2.end()),data2.end());
	for(long long &i : data){
		i=lower_bound(data2.begin(),data2.end(),i)-data2.begin();
	}
	vector<long long> relation(*max_element(data.begin(),data.end())+1);
	for(int i=0;i<N;i++){
		relation[data[i]]=A[i];
		A[i]=data[i];
	}
	int mem=N;
	for(int i=0;i<Q;i++){
		if(query[i][0]==1){
			relation[data[mem]]=query[i][2];
			query[i][2]=data[mem];
			mem++;
		}
	}
	queue<long long> change;
	vector<bool> change2(N,false);
	Fenwick_tree tree(relation.size());
	for(int i=0;i<N;i++){
		tree.add(A[i],1);
		change.emplace(i);
	}
	for(int i=0;i<Q;i++){
		if(query[i][0]==1){
			int k=query[i][1]-1;
			int x=query[i][2];
			A[k]=x;
			if(!change2[k]){
				change.emplace(k);
				change2[k]=true;
			}
		}
		if(query[i][0]==2){
			int t=change.size();
			for(;t--;){
				long long j=change.front();
				change2[j]=false;
				change.pop();
				long long t=tree.max_right(j);
				change.emplace((long long)(N)*t+j);
			}
			while(!change.empty()){
				int t=change.front()/N;
				int j=change.front()%N;
				if(A[j]==-1){
					change.pop();
					continue;
				}
				tree.add(t,-1);
				tree.add(A[j],1);
				A[j]=-1;
				change.pop();
			}
		}
		if(query[i][0]==3){
			int k=query[i][1]-1;
			if(A[k]!=-1){
				printf("%lld\n",relation[A[k]]);
			}
			else{
				printf("%lld\n",relation[tree.max_right(k)]);
			}
		}
	}
}
0