結果

問題 No.649 ここでちょっとQK!
ユーザー CleyLCleyL
提出日時 2022-07-26 12:52:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 488 ms / 3,000 ms
コード長 2,868 bytes
コンパイル時間 2,601 ms
コンパイル使用メモリ 126,324 KB
実行使用メモリ 41,312 KB
最終ジャッジ日時 2023-09-23 05:34:04
合計ジャッジ時間 11,140 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 270 ms
6,144 KB
testcase_04 AC 292 ms
41,312 KB
testcase_05 AC 290 ms
41,308 KB
testcase_06 AC 59 ms
6,096 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 211 ms
20,452 KB
testcase_13 AC 214 ms
20,468 KB
testcase_14 AC 213 ms
20,524 KB
testcase_15 AC 214 ms
20,488 KB
testcase_16 AC 205 ms
20,540 KB
testcase_17 AC 235 ms
22,056 KB
testcase_18 AC 256 ms
23,900 KB
testcase_19 AC 274 ms
25,740 KB
testcase_20 AC 313 ms
27,332 KB
testcase_21 AC 348 ms
29,108 KB
testcase_22 AC 369 ms
31,044 KB
testcase_23 AC 417 ms
32,576 KB
testcase_24 AC 447 ms
34,444 KB
testcase_25 AC 452 ms
36,076 KB
testcase_26 AC 488 ms
37,916 KB
testcase_27 AC 3 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 159 ms
15,432 KB
testcase_31 AC 153 ms
14,956 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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)でintがiterからiterの間にいくつあったかを取得できる
*/

/*
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--;
        }
    }
}
0