結果

問題 No.649 ここでちょっとQK!
ユーザー 25__toma25__toma
提出日時 2018-10-10 00:57:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 512 ms / 3,000 ms
コード長 2,370 bytes
コンパイル時間 1,517 ms
コンパイル使用メモリ 125,400 KB
実行使用メモリ 43,984 KB
最終ジャッジ日時 2024-04-20 19:21:23
合計ジャッジ時間 9,954 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 266 ms
8,144 KB
testcase_04 AC 382 ms
43,984 KB
testcase_05 AC 382 ms
43,976 KB
testcase_06 AC 169 ms
8,012 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 238 ms
22,556 KB
testcase_13 AC 226 ms
22,552 KB
testcase_14 AC 229 ms
22,548 KB
testcase_15 AC 223 ms
22,816 KB
testcase_16 AC 227 ms
22,580 KB
testcase_17 AC 253 ms
24,352 KB
testcase_18 AC 281 ms
26,140 KB
testcase_19 AC 314 ms
28,052 KB
testcase_20 AC 332 ms
29,672 KB
testcase_21 AC 352 ms
31,584 KB
testcase_22 AC 395 ms
33,380 KB
testcase_23 AC 421 ms
35,040 KB
testcase_24 AC 440 ms
36,968 KB
testcase_25 AC 480 ms
38,632 KB
testcase_26 AC 512 ms
40,412 KB
testcase_27 AC 4 ms
5,376 KB
testcase_28 AC 4 ms
5,376 KB
testcase_29 AC 4 ms
5,376 KB
testcase_30 AC 152 ms
17,156 KB
testcase_31 AC 151 ms
17,244 KB
testcase_32 AC 3 ms
5,376 KB
testcase_33 AC 3 ms
5,376 KB
testcase_34 AC 3 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>

#include <vector>
#include <list>
#include<stack>
#include<queue>
#include<array>

#include <set>
#include<map>

#include<string>
#include<stdlib.h>
#include<memory>

#include<algorithm>
#include <functional>
#include<math.h>

#include<fstream>
#include<iomanip>

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7


// 0-indexed
using T = ll;
struct BIT {
	static constexpr ll MAX_N = 210'000;

	BIT(int n_) :n(n_ + 10) {
		fill(bit.begin(), bit.end(), 0);
	}

	T sum(int i) {
		i++;
		ll res = 0;
		while (i > 0) {
			res += bit[i];
			i -= i & -i;
		}
		return res;
	}

	T on(int i) {
		return sum(i) - (i == 0 ? 0 : sum(i - 1));
	}

	void add(int i, T x) {
		i++;
		while (i <= n) {
			bit[i] += x;
			i += i & -i;
		}
	}

//private:
	ll n;
	array<T, MAX_N> bit;
};


//ϐ
ll Q, K, kind;
vector<pll> query;
map<ll, ll> mp, rev;
shared_ptr<BIT> bit;




//Tu֐
//
void input()
{
	cin >> Q >> K;

	ll a = 1, b = 1;
	set<ll> st;
	REP(i, Q) {
		cin >> a;
		if (a == 1) {
			cin >> b;
			st.insert(b);
		}
		query.push_back({ a,b });
	}

	kind = st.size();
	vector<ll> order;
	for (auto num : st)order.push_back(num);
	sort(order.begin(), order.end());
	REP(i, kind) {
		mp[order[i]] = i;
		rev[i] = order[i];
	}
	bit = make_unique<BIT>(kind);
}

ll type2() {
	ll l = -1;
	ll r = kind;
	while (r - l > 1) {
		ll mid = (l + r) / 2;
		if (bit->sum(mid) >= K) {
			r = mid;
		}
		else {
			l = mid;
		}
	}
	bit->add(r, -1);
	return rev[r];
}

//vZ
void calc()
{
	for (const auto& q : query) {
		if (q.first == 1) {
			bit->add(mp[q.second], 1);
		}
		else {
			if (bit->sum(kind) < K)cout << -1 << endl;
			else cout << type2() << endl;
		}
	}

}


//o
void output()
{
	//cout << bit->on(1) << endl;
}


//fobO
void debug()
{
	int N;
	cin>>N;
}


//C֐
int main()
{
	input();
	calc();
	output();
	debug();
	
	return 0;
}
0