結果

問題 No.649 ここでちょっとQK!
ユーザー ei1333333ei1333333
提出日時 2018-02-09 23:16:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 108 ms / 3,000 ms
コード長 1,606 bytes
コンパイル時間 2,315 ms
コンパイル使用メモリ 203,080 KB
実行使用メモリ 8,028 KB
最終ジャッジ日時 2024-04-17 07:58:56
合計ジャッジ時間 5,574 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 25 ms
5,376 KB
testcase_04 AC 80 ms
7,892 KB
testcase_05 AC 79 ms
8,028 KB
testcase_06 AC 65 ms
7,380 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 53 ms
5,548 KB
testcase_13 AC 53 ms
5,680 KB
testcase_14 AC 53 ms
5,548 KB
testcase_15 AC 54 ms
5,548 KB
testcase_16 AC 51 ms
5,544 KB
testcase_17 AC 57 ms
5,804 KB
testcase_18 AC 62 ms
5,928 KB
testcase_19 AC 68 ms
6,324 KB
testcase_20 AC 73 ms
6,444 KB
testcase_21 AC 80 ms
7,112 KB
testcase_22 AC 86 ms
7,080 KB
testcase_23 AC 92 ms
7,300 KB
testcase_24 AC 98 ms
7,424 KB
testcase_25 AC 102 ms
7,684 KB
testcase_26 AC 108 ms
7,808 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 45 ms
5,424 KB
testcase_31 AC 45 ms
5,420 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;


using int64 = long long;

template< class T >
struct BinaryIndexedTree
{
  vector< T > data;

  BinaryIndexedTree(int sz)
  {
    data.assign(++sz, 0);
  }

  T sum(int k)
  {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x)
  {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};

template< class T >
struct AdditionalBIT : BinaryIndexedTree< T >
{
  int curr;

  AdditionalBIT(int sz) : BinaryIndexedTree< T >(sz)
  {
    curr = 1;
    while(curr <= sz) curr <<= 1;
  }

  int lower_bound(T w)
  {
    if(w <= 0) return (0);
    int i = 0;
    for(int k = curr; k > 0; k >>= 1) {
      if(i + k < BinaryIndexedTree< T >::data.size() && BinaryIndexedTree< T >::data[i + k] < w) {
        w -= BinaryIndexedTree< T >::data[i + k];
        i += k;
      }
    }
    return (i);
  }
};

int main()
{
  int Q, K, T[200000];
  int64 V[200000];

  scanf("%d %d", &Q, &K);
  vector< int64 > vs;
  for(int i = 0; i < Q; i++) {
    scanf("%d", &T[i]);
    if(T[i] == 1) {
      scanf("%lld", &V[i]);
      vs.push_back(V[i]);
    }
  }
  sort(begin(vs), end(vs));
  vs.erase(unique(begin(vs), end(vs)), end(vs));
  AdditionalBIT< int > bit(vs.size());
  int sz = 0;
  for(int i = 0; i < Q; i++) {
    if(T[i] == 1) {
      bit.add(lower_bound(begin(vs), end(vs), V[i]) - begin(vs), 1);
      ++sz;
    } else {
      if(sz < K) {
        puts("-1");
      } else {
        auto p = bit.lower_bound(K);
        printf("%lld\n", vs[p]);
        bit.add(p, -1);
        --sz;
      }
    }
  }
}
0