結果

問題 No.649 ここでちょっとQK!
ユーザー tossytossy
提出日時 2018-02-09 23:08:33
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 301 ms / 3,000 ms
コード長 1,623 bytes
コンパイル時間 1,757 ms
コンパイル使用メモリ 168,576 KB
実行使用メモリ 5,912 KB
最終ジャッジ日時 2024-04-17 06:06:35
合計ジャッジ時間 6,527 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 301 ms
5,376 KB
testcase_04 AC 192 ms
5,912 KB
testcase_05 AC 179 ms
5,852 KB
testcase_06 AC 183 ms
5,576 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 101 ms
5,376 KB
testcase_13 AC 99 ms
5,376 KB
testcase_14 AC 97 ms
5,376 KB
testcase_15 AC 102 ms
5,376 KB
testcase_16 AC 100 ms
5,376 KB
testcase_17 AC 115 ms
5,376 KB
testcase_18 AC 128 ms
5,376 KB
testcase_19 AC 135 ms
5,376 KB
testcase_20 AC 146 ms
5,376 KB
testcase_21 AC 157 ms
5,376 KB
testcase_22 AC 167 ms
5,376 KB
testcase_23 AC 178 ms
5,376 KB
testcase_24 AC 188 ms
5,376 KB
testcase_25 AC 202 ms
5,376 KB
testcase_26 AC 208 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 3 ms
5,376 KB
testcase_29 AC 3 ms
5,376 KB
testcase_30 AC 61 ms
5,376 KB
testcase_31 AC 65 ms
5,376 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;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp make_pair
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

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

  priority_queue<long, vector<long>, greater<long>> large;
  priority_queue<long> small;

  rep(i,q){
    int t;
    cin>>t;
    if(t==1){
      long x;
      cin>>x;
      if(small.size() < k) small.push(x);
      else {
        if(small.top() > x){
          large.push(small.top());
          small.pop();
          small.push(x);
        } else {
          large.push(x);
        }
      }
    } else if(t==2){
      if(small.size() < k){
        cout << -1 << "\n";
        continue;
      }
      cout << small.top() << "\n";
      small.pop();
      if(large.size()){
        small.push(large.top());
        large.pop();
      }
    } else {
      assert(false);
    }
  }

  return 0;
}
0