結果

問題 No.649 ここでちょっとQK!
ユーザー 👑 kmjpkmjp
提出日時 2018-02-09 22:31:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 239 ms / 3,000 ms
コード長 1,422 bytes
コンパイル時間 1,499 ms
コンパイル使用メモリ 166,032 KB
実行使用メモリ 8,048 KB
最終ジャッジ日時 2024-04-17 04:53:36
合計ジャッジ時間 5,166 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 239 ms
5,376 KB
testcase_04 AC 68 ms
7,916 KB
testcase_05 AC 68 ms
8,048 KB
testcase_06 AC 64 ms
7,144 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 59 ms
5,436 KB
testcase_13 AC 61 ms
5,436 KB
testcase_14 AC 62 ms
5,444 KB
testcase_15 AC 59 ms
5,568 KB
testcase_16 AC 59 ms
5,696 KB
testcase_17 AC 68 ms
5,736 KB
testcase_18 AC 69 ms
5,824 KB
testcase_19 AC 76 ms
6,212 KB
testcase_20 AC 81 ms
6,336 KB
testcase_21 AC 89 ms
6,976 KB
testcase_22 AC 95 ms
6,852 KB
testcase_23 AC 102 ms
7,060 KB
testcase_24 AC 107 ms
7,316 KB
testcase_25 AC 114 ms
7,572 KB
testcase_26 AC 123 ms
7,708 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 54 ms
5,440 KB
testcase_31 AC 51 ms
5,564 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#undef _P
#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 ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#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 V, int ME> class BIT {
public:
	V bit[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) { e++; while(e<=1<<ME) bit[e-1]+=v,e+=e&-e;}
};
BIT<int,20> bt;

int Q,K;
int A[202020];
ll V[202020];
vector<ll> C;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>Q>>K;
	C.push_back(-1);
	FOR(i,Q) {
		cin>>A[i];
		if(A[i]==1) {
			cin>>V[i];
			C.push_back(V[i]);
		}
	}
	sort(ALL(C));
	
	FOR(i,Q) {
		if(A[i]==1) {
			bt.add(lower_bound(ALL(C),V[i])-C.begin(),1);
		}
		else {
			x=0;
			if(bt(1<<18)<K) {
				cout<<-1<<endl;
			}
			else {
				for(j=18;j>=0;j--) {
					if(bt(x+(1<<j))<K) x+=1<<j;
				}
				cout<<C[x+1]<<endl;
				bt.add(x+1,-1);
			}
			
		}
	}
	
}


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