結果

問題 No.649 ここでちょっとQK!
ユーザー chocoruskchocorusk
提出日時 2018-09-20 14:09:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 518 ms / 3,000 ms
コード長 1,129 bytes
コンパイル時間 2,746 ms
コンパイル使用メモリ 84,996 KB
実行使用メモリ 29,184 KB
最終ジャッジ日時 2023-09-25 10:32:16
合計ジャッジ時間 13,662 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,460 KB
testcase_01 AC 2 ms
5,408 KB
testcase_02 AC 2 ms
5,412 KB
testcase_03 AC 280 ms
5,464 KB
testcase_04 AC 313 ms
29,184 KB
testcase_05 AC 314 ms
29,136 KB
testcase_06 AC 163 ms
4,892 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
5,400 KB
testcase_12 AC 227 ms
15,108 KB
testcase_13 AC 229 ms
15,068 KB
testcase_14 AC 223 ms
14,992 KB
testcase_15 AC 219 ms
15,036 KB
testcase_16 AC 213 ms
15,116 KB
testcase_17 AC 255 ms
16,912 KB
testcase_18 AC 288 ms
18,276 KB
testcase_19 AC 316 ms
18,532 KB
testcase_20 AC 345 ms
19,716 KB
testcase_21 AC 373 ms
21,268 KB
testcase_22 AC 407 ms
22,176 KB
testcase_23 AC 422 ms
23,220 KB
testcase_24 AC 474 ms
24,344 KB
testcase_25 AC 486 ms
25,580 KB
testcase_26 AC 518 ms
26,864 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 3 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 161 ms
11,460 KB
testcase_31 AC 144 ms
11,592 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
5,628 KB
testcase_35 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int bit[200001], n;
 
int sum(int i){
	int s=0;
	while(i>0){
		s+=bit[i];
		i-=(i&(-i));
	}
	return s;
}
 
void add(int i, int x){
	while(i<=n){
		bit[i]+=x;
		i+=(i&(-i));
	}
}

int main()
{
	int q, k;
	cin>>q>>k;
	ll v[200000];
	set<ll> st;
	for(int i=0; i<q; i++){
		int t;
		cin>>t;
		if(t==2){
			v[i]=-1;
		}else{
			ll v0;
			cin>>v0;
			v[i]=v0;
			st.insert(v0);
		}
	}
	n=1;
	map<ll, int> mp;
	ll inv[200001];
	for(auto x:st){
		mp[x]=n;
		inv[n]=x;
		n++;
	}
	n--;
	for(int i=0; i<q; i++){
		if(v[i]>=0){
			add(mp[v[i]], 1);
		}else{
		    if(sum(n)<k){
		        cout<<-1<<endl;
		    }else{
			    int x1=1, x2=n;
			    while(x1!=x2){
				    int x=(x1+x2+1)/2;
				    if(sum(x-1)<k){
				    	x1=x;
				    }else{
				    	x2=x-1;
				    }
			    }
			    cout<<inv[x1]<<endl;
			    add(x1, -1);
		    }
		}
	}
	return 0;
}
0