結果

問題 No.649 ここでちょっとQK!
ユーザー kurarrrkurarrr
提出日時 2018-02-22 12:34:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 75 ms / 3,000 ms
コード長 1,414 bytes
コンパイル時間 1,409 ms
コンパイル使用メモリ 165,392 KB
実行使用メモリ 5,884 KB
最終ジャッジ日時 2023-10-25 04:32:26
合計ジャッジ時間 6,192 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 24 ms
4,348 KB
testcase_04 AC 70 ms
5,884 KB
testcase_05 AC 66 ms
5,824 KB
testcase_06 AC 62 ms
5,684 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 36 ms
4,380 KB
testcase_13 AC 34 ms
4,380 KB
testcase_14 AC 33 ms
4,380 KB
testcase_15 AC 37 ms
4,428 KB
testcase_16 AC 33 ms
4,376 KB
testcase_17 AC 40 ms
4,640 KB
testcase_18 AC 44 ms
4,640 KB
testcase_19 AC 47 ms
4,640 KB
testcase_20 AC 52 ms
4,640 KB
testcase_21 AC 56 ms
4,784 KB
testcase_22 AC 60 ms
4,844 KB
testcase_23 AC 63 ms
4,784 KB
testcase_24 AC 68 ms
4,812 KB
testcase_25 AC 72 ms
4,824 KB
testcase_26 AC 75 ms
4,788 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 29 ms
4,384 KB
testcase_31 AC 28 ms
4,376 KB
testcase_32 AC 1 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 1 ms
4,348 KB
testcase_35 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:32:17: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   32 |     int t; scanf("%d",&t);
      |            ~~~~~^~~~~~~~~
main.cpp:34:20: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   34 |       ll u,v; scanf("%lld",&v);
      |               ~~~~~^~~~~~~~~~~

ソースコード

diff #

#include "bits/stdc++.h"

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#define show_table(n, k, table) rep(i,n){ rep(j,k) cout << table[i][j] << " "; cout << endl;}

template<class T> void chmax(T& a,const T& b){a=max(a,b);}
template<class T> void chmin(T& a,const T& b){a=min(a,b);}

using namespace std;

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<60;
const int MAX_N = 302;

int main(){
  int Q,K; cin >> Q >> K;
  priority_queue<ll> max_que;
  priority_queue<ll,vector<ll>,greater<ll>> min_que;
  rep(i,Q){
    int t; scanf("%d",&t);
    if(t==1){
      ll u,v; scanf("%lld",&v);
      if(max_que.size()<K){
        max_que.push(v);
      }else{
        max_que.push(v);
        v = max_que.top();
        max_que.pop();
        min_que.push(v);
      }
    }else{
      if(max_que.size()<K){
        printf("-1\n");
      }else{
        printf("%lld\n",max_que.top());
        max_que.pop();
        if(!min_que.empty()){
          ll u = min_que.top();
          max_que.push(u);
          min_que.pop();
        }
      }
    }
  }
  return 0;
}
0