結果

問題 No.649 ここでちょっとQK!
ユーザー yuto_okayamayuto_okayama
提出日時 2019-01-20 11:55:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 470 ms / 3,000 ms
コード長 1,602 bytes
コンパイル時間 1,666 ms
コンパイル使用メモリ 159,548 KB
実行使用メモリ 20,916 KB
最終ジャッジ日時 2023-09-29 01:40:35
合計ジャッジ時間 11,729 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 334 ms
4,596 KB
testcase_04 AC 280 ms
20,868 KB
testcase_05 AC 278 ms
20,916 KB
testcase_06 AC 181 ms
9,632 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 203 ms
11,452 KB
testcase_13 AC 205 ms
11,304 KB
testcase_14 AC 204 ms
11,392 KB
testcase_15 AC 203 ms
11,452 KB
testcase_16 AC 196 ms
11,380 KB
testcase_17 AC 230 ms
12,120 KB
testcase_18 AC 251 ms
12,860 KB
testcase_19 AC 274 ms
13,680 KB
testcase_20 AC 309 ms
14,488 KB
testcase_21 AC 332 ms
15,452 KB
testcase_22 AC 360 ms
16,288 KB
testcase_23 AC 383 ms
17,088 KB
testcase_24 AC 416 ms
17,832 KB
testcase_25 AC 444 ms
18,792 KB
testcase_26 AC 470 ms
19,700 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 3 ms
4,376 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 152 ms
9,364 KB
testcase_31 AC 166 ms
9,132 KB
testcase_32 AC 2 ms
4,380 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 #

#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=int(a);i<(int)(b);i++)
#define reps(i,n) for(int i=0;i<=(int)(n);i++)
#define all(x) (x).begin(),(x).end()
#define foreach(u,v) for(auto (u) : (v))
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;

const int inf = 1e9;
const ll linf = 1e18;
const ll mod = 1e9 + 7;
const double eps = 1e-9;

const int MAXN = 200010;
int bit[MAXN+1];

int sum(int i)
{
  int s = 0;
  while(i > 0){
    s += bit[i];
    i -= i & -i;
  }
  return s;
}

void add(int i, int x)
{
  while(i <= MAXN){
    bit[i] += x;
    i += i & -i;
  }
}

int search(int x)
{
  int l = 0, r = MAXN;
  while(r-l > 1){
    int m = (l+r)/2;
    if(sum(m) < x){
      l = m; 
    }else{
      r = m;
    }
  }
  return r;
}

int main()
{
  int q, k;
  cin >> q >> k;

  vl t(q), v;
  rep(i, q){
    cin >> t[i];
    if(t[i] == 1){
      ll vv;
      cin >> vv;
      v.pb(vv);
    }
  }

  vl V;
  foreach(vv, v){
    V.pb(vv);
  }

  sort(all(V));
  V.erase(unique(all(V)), V.end());

  map<ll, int> nv;
  foreach(vv, v){
    int nvv = lower_bound(all(V), vv) - V.begin();
    nv[vv] = nvv;
  }

  auto itv = v.begin();
  rep(i, q){
    if(t[i] == 1){
      add(nv[*itv]+1, 1);
      itv++; 
    }else{
      ll ans = search(k)-1;
      if(ans == MAXN-1) cout << -1 << endl;
      else cout << V[ans] << endl;
      add(ans+1, -1);
    }
  }

  return 0;
}
0