結果

問題 No.649 ここでちょっとQK!
ユーザー puni_kyopropuni_kyopro
提出日時 2019-08-16 20:02:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,595 bytes
コンパイル時間 3,641 ms
コンパイル使用メモリ 88,132 KB
実行使用メモリ 4,648 KB
最終ジャッジ日時 2023-10-23 20:00:22
合計ジャッジ時間 6,219 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 AC 283 ms
4,348 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 3 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 60 ms
4,348 KB
testcase_31 AC 62 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = INT32_MAX / 3;
const ll MOD = 1e9 + 7;

int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };


/******************************************************************************************/

//BinaryIndexTree(siz):長さsizで初期化
//sum(k):区間[0,k]の和を求める
//add(k,x):要素kにxを加える

template<typename T>
struct BinaryIndexTree {

	vector<T> data;

	BinaryIndexTree(int siz)
	{
		//1-indexなので配列は1つ多めに用意する
		data.resize(siz + 1, 0);
	}
	T sum(int k)
	{
		//a_1~a_kまでの和を計算
		T ret = 0;
		for (int i = k; i > 0; i -= (i & -i))
		{
			ret += data[i];
		}
		return ret;
	}

	void add(int k, int x)
	{
		//a_kにxを加算する
		for (int i = k; i < data.size(); i += (i & -i))
		{
			data[i] += x;
		}
	}
};


int main() {

	int q, k;
	cin >> q >> k;
	priority_queue<int> zen;
	priority_queue<int, vector<int>, greater<int> > kou;

	for (int i = 0; i < q; i++)
	{
		int t;
		cin >> t;
		if (t == 1) {
			//挿入
			int v;
			cin >> v;
			if (zen.size() < k) {
				zen.push(v);
			}
			else
			{
				int tp = zen.top();
				if (v < tp) {
					zen.pop();
					zen.push(v);
					kou.push(tp);
				}
				else
				{
					kou.push(v);
				}
			}
		}
		else
		{
			if (zen.size() < k) {
				cout << "-1" << endl;
			}
			else
			{
				cout << zen.top() << endl;
				zen.pop();
				if (kou.size() > 1) {
					int tp = kou.top();
					kou.pop();
					zen.push(tp);
				}
			}
		}
	}



	

	return 0;
}
0