結果

問題 No.2809 Sort Query
ユーザー highlighterhighlighter
提出日時 2024-04-22 23:59:24
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 556 ms / 2,000 ms
コード長 2,391 bytes
コンパイル時間 4,018 ms
コンパイル使用メモリ 266,200 KB
実行使用メモリ 40,900 KB
最終ジャッジ日時 2024-07-12 21:00:33
合計ジャッジ時間 36,960 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 556 ms
35,468 KB
testcase_02 AC 387 ms
35,448 KB
testcase_03 AC 405 ms
36,256 KB
testcase_04 AC 370 ms
35,384 KB
testcase_05 AC 376 ms
35,388 KB
testcase_06 AC 263 ms
31,968 KB
testcase_07 AC 280 ms
31,832 KB
testcase_08 AC 260 ms
33,268 KB
testcase_09 AC 260 ms
32,964 KB
testcase_10 AC 257 ms
31,900 KB
testcase_11 AC 271 ms
33,724 KB
testcase_12 AC 267 ms
33,816 KB
testcase_13 AC 275 ms
33,876 KB
testcase_14 AC 269 ms
33,816 KB
testcase_15 AC 272 ms
33,792 KB
testcase_16 AC 271 ms
33,784 KB
testcase_17 AC 274 ms
33,848 KB
testcase_18 AC 267 ms
33,832 KB
testcase_19 AC 274 ms
33,808 KB
testcase_20 AC 270 ms
33,756 KB
testcase_21 AC 489 ms
40,840 KB
testcase_22 AC 487 ms
40,812 KB
testcase_23 AC 496 ms
40,900 KB
testcase_24 AC 488 ms
40,828 KB
testcase_25 AC 490 ms
40,832 KB
testcase_26 AC 422 ms
36,596 KB
testcase_27 AC 427 ms
36,608 KB
testcase_28 AC 437 ms
36,684 KB
testcase_29 AC 422 ms
36,828 KB
testcase_30 AC 428 ms
36,772 KB
testcase_31 AC 216 ms
31,532 KB
testcase_32 AC 217 ms
31,772 KB
testcase_33 AC 215 ms
31,476 KB
testcase_34 AC 213 ms
31,364 KB
testcase_35 AC 215 ms
31,436 KB
testcase_36 AC 229 ms
33,784 KB
testcase_37 AC 228 ms
33,868 KB
testcase_38 AC 227 ms
33,800 KB
testcase_39 AC 228 ms
33,804 KB
testcase_40 AC 228 ms
33,724 KB
testcase_41 AC 408 ms
32,988 KB
testcase_42 AC 412 ms
33,060 KB
testcase_43 AC 398 ms
32,700 KB
testcase_44 AC 397 ms
32,852 KB
testcase_45 AC 406 ms
33,704 KB
testcase_46 AC 341 ms
33,852 KB
testcase_47 AC 344 ms
32,720 KB
testcase_48 AC 338 ms
32,844 KB
testcase_49 AC 345 ms
32,892 KB
testcase_50 AC 339 ms
32,792 KB
testcase_51 AC 441 ms
32,808 KB
testcase_52 AC 377 ms
32,648 KB
testcase_53 AC 269 ms
34,392 KB
testcase_54 AC 229 ms
32,768 KB
testcase_55 AC 273 ms
33,888 KB
testcase_56 AC 262 ms
27,632 KB
testcase_57 AC 214 ms
24,008 KB
testcase_58 AC 201 ms
22,056 KB
testcase_59 AC 233 ms
25,676 KB
testcase_60 AC 253 ms
22,068 KB
testcase_61 AC 306 ms
27,104 KB
testcase_62 AC 208 ms
23,120 KB
testcase_63 AC 287 ms
28,948 KB
testcase_64 AC 352 ms
31,972 KB
testcase_65 AC 190 ms
19,260 KB
testcase_66 AC 2 ms
6,940 KB
testcase_67 AC 2 ms
6,940 KB
testcase_68 AC 2 ms
6,940 KB
testcase_69 AC 2 ms
6,944 KB
testcase_70 AC 2 ms
6,940 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(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N,Q;
	cin >> N >> Q;
	vector<long long> A(N);
	for(int i=0;i<N;i++){
		cin >> A[i];
	}
	vector<long long> data=A;
	data.reserve(N+Q);
	vector<vector<long long>> query(Q);
	for(int i=0;i<Q;i++){
		int c;
		cin >> c;
		if(c==1){
			int k;
			long long x;
			cin >> k >> x;
			vector<long long> vec={c,k,x};
			data.emplace_back(x);
			query[i]=vec;
			continue;
		}
		if(c==2){
			vector<long long> vec={c};
			query[i]=vec;
			continue;
		}
		int k;
		cin >> k;
		vector<long long> vec={c,k};
		query[i]=vec;
	}
	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;
	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;
			change.emplace(k);
		}
		if(query[i][0]==2){
			int t=change.size();
			for(;t--;){
				long long j=change.front();
				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){
				cout << relation[A[k]] << '\n';
			}
			else{
				cout << relation[tree.max_right(k)] << '\n';
			}
		}
	}
}
0