結果

問題 No.649 ここでちょっとQK!
ユーザー Keiichi HirobeKeiichi Hirobe
提出日時 2022-10-04 22:57:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 287 ms / 3,000 ms
コード長 2,428 bytes
コンパイル時間 4,814 ms
コンパイル使用メモリ 266,272 KB
実行使用メモリ 5,912 KB
最終ジャッジ日時 2023-08-28 22:49:40
合計ジャッジ時間 12,151 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 287 ms
4,376 KB
testcase_04 AC 176 ms
5,912 KB
testcase_05 AC 170 ms
5,668 KB
testcase_06 AC 169 ms
5,732 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 95 ms
4,376 KB
testcase_13 AC 93 ms
4,428 KB
testcase_14 AC 91 ms
4,380 KB
testcase_15 AC 97 ms
4,376 KB
testcase_16 AC 91 ms
4,376 KB
testcase_17 AC 105 ms
4,376 KB
testcase_18 AC 116 ms
4,376 KB
testcase_19 AC 126 ms
4,532 KB
testcase_20 AC 135 ms
4,380 KB
testcase_21 AC 145 ms
4,624 KB
testcase_22 AC 155 ms
4,592 KB
testcase_23 AC 165 ms
4,608 KB
testcase_24 AC 178 ms
4,652 KB
testcase_25 AC 187 ms
4,668 KB
testcase_26 AC 200 ms
4,596 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 62 ms
4,380 KB
testcase_31 AC 62 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
// clang-format off
#define rep(i, s ,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using ll = long long;
// 2^60
#define INF (1LL << 60)
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
using namespace atcoder;
using Graph = vector<vector<int>>;
template <typename T> ostream &operator<<(ostream &s, vector<vector<vector<T>>> const &v) { for (int i = 0; i < int(v.size()); ++i) { s << "[" << i << "]" << endl; s << v[i];} return s;}
template <typename T> ostream &operator<<(ostream &s, vector<vector<T>> const &v) { for (int i = 0; i < int(v.size()); ++i ){ s << v[i];} return s;}
template <typename T> ostream &operator<<(ostream &s, vector<T> const &v) { for (int i = 0; i < int(v.size()); ++i) { s << v[i]; if (i != int(v.size()) - 1) { s << ",";}} s << endl; return s;}
// clang-format on

// 幅優先の例
// 入力: グラフ G と,探索の始点 s
// 出力: s から各頂点への最短路長を表す配列
vector<int> BFS(const Graph &G, int s)
{
    int N = (int)G.size(); // 頂点数
    // vector<bool> seen(N, false);
    vector<int> dist(N, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;

    dist[s] = 0;
    que.push(s);

    while (!que.empty())
    {
        int v = que.front();
        que.pop();

        for (int x : G[v])
        {
            if (dist[x] != -1)
                continue;

            dist[x] = dist[v] + 1;
            que.push(x);
        }
    }
    return dist;
}

int main()
{
    cout << fixed << setprecision(16);
    int q, k;
    cin >> q >> k;
    priority_queue<ll> q1;
    priority_queue<ll, vector<ll>, std::greater<ll>> q2;

    rep(i, 0, q)
    {
        int which;
        cin >> which;
        if (which == 1)
        {
            ll v;
            cin >> v;
            q1.push(v);
            if (int(q1.size()) >= k)
            {
                ll exch = q1.top();
                q1.pop();
                q2.push(exch);
            }
        }
        else
        {
            if (q2.size() == 0)
            {
                cout << -1 << endl;
            }
            else
            {
                cout << q2.top() << endl;
                q2.pop();
            }
        }
    }
}
0