結果

問題 No.649 ここでちょっとQK!
ユーザー xuzijian629
提出日時 2018-09-05 15:22:39
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 272 ms / 3,000 ms
コード長 1,455 bytes
コンパイル時間 1,283 ms
コンパイル使用メモリ 111,076 KB
最終ジャッジ日時 2025-01-06 12:51:10
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <cassert>
#pragma GCC optimize("O3")
#pragma comment(linker, "STACK:36777216")
using namespace std;
using i64 = int64_t;
constexpr i64 MOD = 1e9 + 7;
using vi = vector<i64>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    priority_queue<i64> small;
    priority_queue<i64, vi, greater<>> big;
    int q, k;
    cin >> q >> k;
    int type;
    i64 v;
    for (int i = 0; i < q; i++) {
        cin >> type;
        if (type == 1) {
            cin >> v;
            if (small.size() < k) {
                small.push(v);
            } else {
                i64 t = small.top();
                if (v > t) {
                    big.push(v);
                } else {
                    big.push(small.top());
                    small.pop();
                    small.push(v);
                }
            }
        } else {
            if (small.size() < k) {
                cout << "-1" << endl;
            } else {
                cout << small.top() << endl;
                if (big.size()) {
                    small.pop();
                    small.push(big.top());
                    big.pop();
                } else {
                    small.pop();
                }
            }
        }
    }
}
0