結果

問題 No.649 ここでちょっとQK!
ユーザー aa
提出日時 2018-11-01 20:50:11
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 235 ms / 3,000 ms
コード長 3,476 bytes
コンパイル時間 1,184 ms
コンパイル使用メモリ 110,840 KB
実行使用メモリ 19,404 KB
最終ジャッジ日時 2023-08-12 16:21:33
合計ジャッジ時間 6,476 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 22 ms
5,456 KB
testcase_04 AC 146 ms
19,404 KB
testcase_05 AC 140 ms
19,356 KB
testcase_06 AC 63 ms
6,996 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 91 ms
11,040 KB
testcase_13 AC 89 ms
10,976 KB
testcase_14 AC 88 ms
11,040 KB
testcase_15 AC 92 ms
10,988 KB
testcase_16 AC 89 ms
11,048 KB
testcase_17 AC 98 ms
12,048 KB
testcase_18 AC 114 ms
12,428 KB
testcase_19 AC 123 ms
13,356 KB
testcase_20 AC 149 ms
13,700 KB
testcase_21 AC 156 ms
14,452 KB
testcase_22 AC 167 ms
15,232 KB
testcase_23 AC 176 ms
16,000 KB
testcase_24 AC 189 ms
16,564 KB
testcase_25 AC 204 ms
17,272 KB
testcase_26 AC 235 ms
18,088 KB
testcase_27 AC 3 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 71 ms
9,132 KB
testcase_31 AC 68 ms
9,088 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putbd cout << "---------------------------------------------" << endl;
#define putln(x) cout << x << endl;
#define debug(x) cerr << #x << "=" << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);
#define yuiyui 0

typedef long long ll;
typedef unsigned long long ul;
typedef pair<int, int> intP;
typedef pair<ll, ll> llP;
typedef pair<ul, ul> ulP;
typedef complex<double> comp;
typedef vector <int> vec;
typedef vector <ll> vecll;
typedef vector <ul> vecul;
typedef vector <double> vecd;
typedef vector <vec> mat;
typedef vector <vecll> matll;
typedef vector <vecul> matul;
typedef vector <vecd> matd;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 200020;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e18;
const ll MOD = 1e9+7;

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

//********************************template END****************************************//

template<typename T>
struct BIT
{
	int N, K;
	vector<T> bit;

	BIT (int X)
	{
		bit = vector<T>(X+1, 0);
		N = X+1;
		K = pow(2, (int)(log(X)/log(2)));
	}

	void add(int idx, T w)
	{
		for (int x = idx; x <= N; x += x&-x)
		{
			bit[x] += w;
		}
	}

	T sum(int idx)
	{
		T res = 0;
		for (int x = idx; x > 0; x -= x&-x) res += bit[x];
		return res;
	}

	int lb(T w)
	{
		int k = K, idx = 0;

		while(k > 0)
		{
			if (idx + k <= N && w > bit[idx+k])
			{
				w -= bit[idx+k];
				idx += k;
			}
			k >>= 1;
		}

		return idx+1;
	}

	void chmax(int idx, T w)
	{
		for (int x = idx; x <= N; x += x&-x)
		{
			bit[x] = max(bit[x], w);
		}
	}


	T getmax(int idx)
	{
		T res = 0;
		for (int x = idx; x > 0; x -= x&-x) res = max(res, bit[x]);
		return res;
	}

};


void solve(void){

	int Q, K;
	ll q, x;
	scanf("%d%d\n", &Q, &K);
	vecll xs, qs;
	while(Q--)
	{
		scanf("%lld\n", &q);
		if (q==1)
		{
			scanf("%lld\n", &x);
			xs.pb(x);
			qs.pb(x);
		}
		else
		{
			qs.pb(-1);
		}
	}

	sort(all(xs));
	uniq(xs);
	int n = xs.size();

	BIT<int> bit(MAX);

	map<ll, int> mp;

	rep(n, i) mp[xs[i]] = i+1;

	int cnt = 0;

	for (ll q : qs)
	{
		if (q >= 0)
		{
			bit.add(mp[q], 1);
			cnt++;
		}
		else
		{
			if (cnt < K)
			{
				printf("-1\n");
				continue;
			}
			int idx = bit.lb(K);
			printf("%lld\n", xs[idx-1]);
			bit.add(idx, -1);
			cnt--;
		}
	}

}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return yuiyui;
}
0