結果

問題 No.649 ここでちょっとQK!
ユーザー ゆきのんゆきのん
提出日時 2020-12-09 01:53:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 290 ms / 3,000 ms
コード長 2,605 bytes
コンパイル時間 1,834 ms
コンパイル使用メモリ 179,236 KB
実行使用メモリ 9,376 KB
最終ジャッジ日時 2023-10-19 03:13:20
合計ジャッジ時間 8,797 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 290 ms
7,260 KB
testcase_04 AC 185 ms
9,376 KB
testcase_05 AC 187 ms
9,376 KB
testcase_06 AC 184 ms
9,376 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 115 ms
6,764 KB
testcase_13 AC 115 ms
6,764 KB
testcase_14 AC 112 ms
6,764 KB
testcase_15 AC 115 ms
6,764 KB
testcase_16 AC 114 ms
6,764 KB
testcase_17 AC 126 ms
6,920 KB
testcase_18 AC 136 ms
7,076 KB
testcase_19 AC 149 ms
7,232 KB
testcase_20 AC 159 ms
7,388 KB
testcase_21 AC 172 ms
8,592 KB
testcase_22 AC 184 ms
8,752 KB
testcase_23 AC 199 ms
8,908 KB
testcase_24 AC 206 ms
9,064 KB
testcase_25 AC 217 ms
9,220 KB
testcase_26 AC 229 ms
9,376 KB
testcase_27 AC 3 ms
4,348 KB
testcase_28 AC 3 ms
4,348 KB
testcase_29 AC 3 ms
4,348 KB
testcase_30 AC 80 ms
6,764 KB
testcase_31 AC 79 ms
6,764 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
//#include<atcoder/all>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace atcoder;
//using namespace boost::multiprecision;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const ll mod=998244353;
const ll LINF=1ll<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


template< typename T >
struct BinaryIndexedTree{

    //0-indexed
    vector< T > bit;

    BinaryIndexedTree(int sz) : bit(sz, 0) {}

    //return a[0, k)
    T sum(int k){
        assert(0 <= k && k <= bit.size());
        T ret = 0;
        for (--k; k >= 0; k = (k&(k+1))-1) ret += bit[k];
        return ret;
    }
    
    //return a[l, r)
    T sum(int l, int r){
        return sum(r) - sum(l);
    }

    //a[k] += k
    void add(int k, T x){
        for (; k < bit.size(); k |= k+1) bit[k] += x;
    }

    //a[k] = x
    void update(int k, T x){
        add(k, x - sum(k, k + 1));
    }


    // sum(ret) >= x を満たす最小のret
    T lower_bound(T x) {
        if(x <= 0) return 0;
        T ret = 0;
        int i = 1;
        while((i<<1) < bit.size()) i <<= 1;
        for(;i;i>>=1){
            if(ret+i-1 < bit.size() && bit[ret+i-1] < x){
                x -= bit[ret + i - 1];
                ret += i;
            }
        }
        return ret + 1;
    }
};


int main(){
    int q, k;cin >> q >> k;
    BinaryIndexedTree<int> bit(200001);
    vector<P> v(q, mp(0,0));
    vector<ll> x;
    for (int i = 0; i < q; i++) {
        int t;cin >> t;
        if(t == 1){
            ll X;cin >> X;
            x.pb(X);
            v[i] = mp(t, X);
        }
        else{
            v[i] = mp(t, 0);
        }
    }
    sort(ALL(x));
    x.erase(unique(ALL(x)), x.end());
    for (int i = 0; i < q; i++) {
        if(v[i].fs == 1){
            auto p = lower_bound(ALL(x), v[i].sc) - x.begin();
            bit.add(p, 1);
        }
        else{
            auto p = bit.lower_bound(k);
            if(p > 200000){
                cout << -1 << endl;
            }
            else{
                cout << x[p - 1] << endl;
                bit.add(p - 1, -1);
            }
        }
    }
    return 0;
}
0