結果

問題 No.649 ここでちょっとQK!
ユーザー 👑 CleyLCleyL
提出日時 2022-07-26 12:52:20
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 402 ms / 3,000 ms
コード長 2,868 bytes
コンパイル時間 1,216 ms
コンパイル使用メモリ 123,260 KB
最終ジャッジ日時 2025-01-30 14:15:51
ジャッジサーバーID
(参考情報)
judge4 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

//yukicoder@cpp17
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <complex>
#include <cctype>
#include <utility>
#include <climits>
#include <numeric>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 998244353;
const ll MODx = 1000000007;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62LL)-1;
const double EPS = (1e-10);
P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }
/*
cout << fixed << setprecision(n) << //n
min(max)_element(iter,iter)()
count(iter,iter,int)intiteriter
*/
/*
function corner below
*/
template<typename T>
struct BIT{//1_Indexed
int n;
vector<T> bit;
BIT(int n_):n(n_+1),bit(n,0){}
T sum(int a){
int ret = 0;
for(int i = a; i > 0; i -= i & -i) ret += bit[i];
return ret;
}
void add(int a,int w){
for(int i = a; i <= n; i += i & -i)bit[i] += w;
}
T query(int r,int l){
return sum(l-1)-sum(r-1);
}
int lower_bound(int x){
if(x <= 0)return 0;
int nw = 0;
int r = 1;
while(r*2 < n) r*=2;
for(int i = r; i > 0; i /= 2){
if(nw + i <= n && bit[nw+i] < x){
x -= bit[nw+i];
nw += i;
}
}
return nw+1;
}
};
/*
Function corner above
*/
__attribute__((constructor))
void initial() {
cin.tie(0);
ios::sync_with_stdio(false);
}
int main(){
int q,k;cin>>q>>k;
set<long long> X;
vector<pair<int,long long>> l(q);
for(int i = 0; q > i; i++){
cin>>l[i].first;
if(l[i].first == 1)cin>>l[i].second,X.insert(l[i].second);
else l[i].second = -1;
}
map<long long, long long> Z,reZ;
int nw = 1;
for(auto x: X){
Z[x] = nw;
reZ[nw] = x;
nw++;
}
BIT<int> B(X.size());
nw = 0;
for(int i = 0; q > i; i++){
if(l[i].first == 1){
B.add(Z[l[i].second],1);
nw++;
}else{
if(nw < k){
cout << -1 << endl;
continue;
}
auto re = B.lower_bound(k);
cout << reZ[re] << endl;
B.add(re,-1);
nw--;
}
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0