結果

問題 No.2809 Sort Query
ユーザー 👑 kmjpkmjp
提出日時 2024-07-12 23:38:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,166 bytes
コンパイル時間 3,063 ms
コンパイル使用メモリ 215,948 KB
実行使用メモリ 59,724 KB
最終ジャッジ日時 2024-07-12 23:39:21
合計ジャッジ時間 56,869 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,696 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 686 ms
33,860 KB
testcase_12 AC 572 ms
33,864 KB
testcase_13 WA -
testcase_14 AC 522 ms
33,992 KB
testcase_15 AC 506 ms
33,860 KB
testcase_16 AC 552 ms
33,860 KB
testcase_17 AC 505 ms
33,860 KB
testcase_18 AC 509 ms
35,824 KB
testcase_19 AC 552 ms
33,864 KB
testcase_20 AC 508 ms
33,860 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 690 ms
32,496 KB
testcase_32 AC 701 ms
34,296 KB
testcase_33 AC 681 ms
32,628 KB
testcase_34 AC 651 ms
32,492 KB
testcase_35 AC 694 ms
32,624 KB
testcase_36 AC 500 ms
35,816 KB
testcase_37 AC 516 ms
33,860 KB
testcase_38 AC 508 ms
33,856 KB
testcase_39 AC 551 ms
35,756 KB
testcase_40 AC 499 ms
33,864 KB
testcase_41 AC 880 ms
33,776 KB
testcase_42 AC 846 ms
33,772 KB
testcase_43 AC 832 ms
33,772 KB
testcase_44 AC 883 ms
33,780 KB
testcase_45 AC 854 ms
33,908 KB
testcase_46 AC 820 ms
33,904 KB
testcase_47 AC 784 ms
33,904 KB
testcase_48 AC 838 ms
33,932 KB
testcase_49 AC 816 ms
33,644 KB
testcase_50 AC 863 ms
33,648 KB
testcase_51 AC 965 ms
24,428 KB
testcase_52 AC 886 ms
24,940 KB
testcase_53 AC 907 ms
24,300 KB
testcase_54 AC 857 ms
24,432 KB
testcase_55 AC 888 ms
24,436 KB
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,Q;
ll A[303030];
int X[303030],Y[303030];
ll Z[303030];

template<class V, int ME> class BIT {
public:
	V bit[1<<ME],val[1<<ME];
	V operator()(int e) {if(e<0) return 0;V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;}
	void add(int e,V v) { val[e++]+=v; while(e<=1<<ME) bit[e-1]+=v,e+=e&-e;}
	void set(int e,V v) { add(e,v-val[e]);}
	int lower_bound(V val) {
		V tv=0; int i,ent=0;
		for(i=ME-1;i>=0;i--) if(tv+bit[ent+(1<<i)-1]<val) tv+=bit[ent+(1<<i)-1],ent+=(1<<i);
		return ent;
	}
};
BIT<ll,20> num,val;
set<int> U;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	vector<ll> Vs;
	cin>>N>>Q;
	FOR(i,N) {
		cin>>A[i];
		Vs.push_back(A[i]);
		U.insert(i);
	}
	FOR(i,Q) {
		cin>>X[i];
		if(X[i]==1) {
			cin>>Y[i]>>Z[i];
			Y[i]--;
			Vs.push_back(Z[i]);
		}
		else if(X[i]==3) {
			cin>>Y[i];
			Y[i]--;
		}
	}
	sort(ALL(Vs));
	Vs.erase(unique(ALL(Vs)),Vs.end());
	FOR(i,N) {
		A[i]=lower_bound(ALL(Vs),A[i])-Vs.begin();
	}
	FOR(i,Q) {
		if(X[i]==1) {
			x=Y[i];
			if(U.count(x)==0) {
				num.add(x,-1);
				val.add(A[x],-1);
				U.insert(x);
			}
			A[x]=lower_bound(ALL(Vs),Z[i])-Vs.begin();
		}
		else if(X[i]==2) {
			FORR(x,U) {
				num.add(x,1);
				val.add(A[x],1);
			}
			U.clear();
		}
		else {
			x=Y[i];
			if(U.count(x)) {
				cout<<Vs[A[x]]<<endl;
			}
			else {
				x=num(x);
				y=val.lower_bound(x);
				cout<<Vs[y]<<endl;
			}
		}
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0