結果

問題 No.649 ここでちょっとQK!
ユーザー donkorin_donkorin_
提出日時 2018-11-30 17:45:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 272 ms / 3,000 ms
コード長 2,955 bytes
コンパイル時間 2,388 ms
コンパイル使用メモリ 174,188 KB
実行使用メモリ 10,036 KB
最終ジャッジ日時 2023-09-09 06:32:21
合計ジャッジ時間 7,589 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,516 KB
testcase_01 AC 2 ms
4,476 KB
testcase_02 AC 3 ms
4,568 KB
testcase_03 AC 272 ms
7,764 KB
testcase_04 AC 76 ms
9,840 KB
testcase_05 AC 75 ms
9,992 KB
testcase_06 AC 70 ms
9,764 KB
testcase_07 AC 3 ms
4,576 KB
testcase_08 AC 3 ms
4,512 KB
testcase_09 AC 3 ms
4,484 KB
testcase_10 AC 3 ms
4,612 KB
testcase_11 AC 3 ms
4,584 KB
testcase_12 AC 65 ms
7,172 KB
testcase_13 AC 65 ms
7,104 KB
testcase_14 AC 64 ms
7,100 KB
testcase_15 AC 64 ms
7,236 KB
testcase_16 AC 63 ms
7,176 KB
testcase_17 AC 68 ms
7,332 KB
testcase_18 AC 76 ms
7,476 KB
testcase_19 AC 83 ms
7,680 KB
testcase_20 AC 89 ms
7,720 KB
testcase_21 AC 96 ms
8,988 KB
testcase_22 AC 102 ms
9,144 KB
testcase_23 AC 109 ms
9,300 KB
testcase_24 AC 115 ms
9,504 KB
testcase_25 AC 122 ms
9,528 KB
testcase_26 AC 128 ms
10,036 KB
testcase_27 AC 3 ms
4,572 KB
testcase_28 AC 3 ms
4,620 KB
testcase_29 AC 4 ms
4,788 KB
testcase_30 AC 55 ms
7,072 KB
testcase_31 AC 54 ms
7,160 KB
testcase_32 AC 3 ms
4,520 KB
testcase_33 AC 2 ms
4,812 KB
testcase_34 AC 3 ms
4,576 KB
testcase_35 AC 3 ms
4,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(x, a) for(auto &x : a)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
#define F first
#define S second
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

template <class Abel> struct BIT {
    vector<Abel> dat;
    Abel UNITY_SUM = 0;                     // to be set

    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) {
        dat.resize(n + 1);
        for (int i = 0; i < (int)dat.size(); ++i) dat[i] = UNITY_SUM;
    }

    /* a is 1-indexed */
    inline void add(int a, Abel x) {
        for (int i = a; i < (int)dat.size(); i += i & -i)
            dat[i] = dat[i] + x;
    }

    /* [1, a], a is 1-indexed */
    inline Abel sum(int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i)
            res = res + dat[i];
        return res;
    }

    /* [a, b), a and b are 1-indexed */
    inline Abel sum(int a, int b) {
        return sum(b - 1) - sum(a - 1);
    }

    /* k-th number (k is 0-indexed) */
    int get(long long k) {
        ++k;
        int res = 0;
        int N = 1; while (N < (int)dat.size()) N *= 2;
        for (int i = N / 2; i > 0; i /= 2) {
            if (res + i < (int)dat.size() && dat[res + i] < k) {
                k = k - dat[res + i];
                res = res + i;
            }
        }
        return res + 1;
    }
};

int q, k;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> q >> k;
    BIT<ll> bit(200005);
    vll t(q), v(q), query;
    rep(i, 0, q) {
      cin >> t[i];
      if (t[i] == 1) {
        cin >> v[i];
        query.pb(v[i]);
      }
    }
    sort(ALL(query));
    query.erase(unique(ALL(query)), query.end());
    rep(i, 0, q) {
      if (t[i] == 1) {
        int p = lower_bound(ALL(query), v[i]) - query.begin();
        bit.add(p + 1, 1);
      } else {
        int sz = bit.sum(200005);
        if (k > sz) {
          cout << -1 << endl;
        } else {
          int p = bit.get(k - 1);
          cout << query[p - 1] << endl;
          bit.add(p, -1);
        }
      }
    }
    return 0;
}

0