結果
| 問題 |
No.649 ここでちょっとQK!
|
| コンテスト | |
| ユーザー |
Kutimoti_T
|
| 提出日時 | 2018-05-27 09:53:06 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 280 ms / 3,000 ms |
| コード長 | 2,587 bytes |
| コンパイル時間 | 1,523 ms |
| コンパイル使用メモリ | 172,364 KB |
| 実行使用メモリ | 9,972 KB |
| 最終ジャッジ日時 | 2024-06-28 18:24:16 |
| 合計ジャッジ時間 | 6,721 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
/* include file*/
#include <functional>
#include <vector>
using namespace std;
template <class Monoid>
struct Segment {
using Func = function<Monoid(Monoid, Monoid)>;
vector<Monoid> node;
Monoid ide;
int n = 1;
Func bin_f;
Func update_f;
Segment(const vector<Monoid>& init, Monoid ide_, Func f_, Func u_f)
: bin_f(f_), ide(ide_), update_f(u_f) {
int sz = init.size();
while (n < sz) n *= 2;
node.assign(n * 2 - 1, ide);
for (int i = 0; i < sz; i++) node[i + n - 1] = init[i];
for (int i = n - 2; i >= 0; i--)
node[i] = bin_f(node[i * 2 + 1], node[i * 2 + 2]);
}
void update(int i, Monoid x) {
i += n - 1;
node[i] = update_f(node[i], x);
while (i) {
i = (i - 1) / 2;
node[i] = bin_f(node[i * 2 + 1], node[i * 2 + 2]);
}
}
Monoid get_inter(int a, int b, int k = 0, int l = 0, int r = -1) {
if (r < 0) r = n;
if (a <= l && r <= b) return node[k];
if (r <= a || b <= l) return ide;
Monoid lm = get_inter(a, b, k * 2 + 1, l, (l + r) / 2);
Monoid rm = get_inter(a, b, k * 2 + 2, (l + r) / 2, r);
return bin_f(lm, rm);
}
int lower_bound(int v,int k = 0,int l = 0,int r = -1){
if(r < 0) r = n;
if(l + 1 == r){
return l;
}
if(node[k * 2 + 1] < v){
return lower_bound(v - node[k * 2 + 1],k * 2 + 2,(l + r) / 2,r);
}
else{
return lower_bound(v,k * 2 + 1,l,(l + r) / 2);
}
}
};
// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2730414#1
// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2730425#1
int Q,K;
int main(){
cin >> Q >> K;
vector<int> q(Q);
vector<i64> v(Q);
vector<i64> vec;
rep(i,0,Q - 1){
cin >> q[i];
if(q[i] == 1){
cin >> v[i];
vec.push_back(v[i]);
}
}
sort(vec.begin(),vec.end());
vec.erase(unique(vec.begin(),vec.end()),vec.end());
rep(i,0,Q - 1) v[i] = lower_bound(vec.begin(),vec.end(),v[i]) - vec.begin();
Segment<int> seg(vector<int>(vec.size(),0),0,[](int a,int b){
return a + b;
},[](int a,int b){
return a + b;
});
vector<i64> ans;
rep(i,0,Q - 1){
if(q[i] == 1){
seg.update(v[i],1);
}
else{
if(seg.node[0] < K) ans.push_back(-1);
else{
ans.push_back(seg.lower_bound(K));
seg.update(ans.back(),-1);
}
}
}
for(int i : ans){
if(i == -1){
cout << -1 << endl;
}
else{
cout << vec[i] << endl;
}
}
}
Kutimoti_T