結果

問題 No.3298 K-th Slime
ユーザー srjywrdnprkt
提出日時 2025-10-09 17:22:40
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 1,405 bytes
コンパイル時間 3,497 ms
コンパイル使用メモリ 281,208 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-10-09 17:22:46
合計ジャッジ時間 4,836 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/modint>

using namespace std;
//using namespace atcoder;
using ll = long long;
//using mint = modint998244353;

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    /*
       priority_queueで先頭K個と後ろを管理
    */

    ll N, K, Q;
    cin >> N >> K >> Q;
    priority_queue<ll> que1;
    priority_queue<ll, vector<ll>, greater<ll>> que2;
    
    auto push=[&](ll x)->void{
        if (que1.size() < K){
            que1.push(x);
            return;
        }
        if (x >= que1.top()) que2.push(x);
        else{
            ll y = que1.top();
            que1.pop();
            que1.push(x);
            que2.push(y);
        }
    };
    auto pop=[&]()->void{
        que1.pop();
        if (!que2.empty()){
            ll y = que2.top();
            que2.pop();
            que1.push(y);
        }
    };
    auto top=[&]()->ll{
        return que1.top();
    };

    for (int i=0; i<N; i++){
        ll x;
        cin >> x;
        push(x);
    }
    while(Q--){
        ll t;
        cin >> t;
        if (t == 1){
            ll x;
            cin >> x;
            push(x);
        }
        else if (t == 2){
            ll x, y;
            cin >> y;
            x = top();
            pop();
            push(x+y);
        }
        else{
            cout << top() << '\n';
        }
    }

    return 0;
}
0