結果

問題 No.3298 K-th Slime
ユーザー toufu24
提出日時 2025-10-05 14:25:28
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 2,005 bytes
コンパイル時間 5,050 ms
コンパイル使用メモリ 334,016 KB
実行使用メモリ 9,856 KB
最終ジャッジ日時 2025-10-05 14:25:48
合計ジャッジ時間 10,316 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 15 TLE * 1 -- * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

#define all(v) v.begin(), v.end()
#define SORT(v) sort(v.begin(), v.end())
#define RSORT(v) sort(v.rbegin(), v.rend())
#define REVERSE(v) reverse(v.begin(), v.end())
#define ll long
#define ld long double

#define int ll

int32_t main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> a(n);
    multiset<int> left, right;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (left.size() < k) {
            left.insert(a[i]);
        } else {
            if (*left.rbegin() > a[i]) {
                right.insert(*left.rbegin());
                left.erase(left.find(*left.rbegin()));
                left.insert(a[i]);
            } else {
                right.insert(a[i]);
            }
        }
    }

    while (q--) {
        int op;
        cin >> op;
        if (op == 1) {
            int x;
            cin >> x;
            if (left.size() < k) {
                left.insert(x);
            } else {
                if (*left.rbegin() > x) {
                    right.insert(*left.rbegin());
                    left.erase(left.find(*left.rbegin()));
                    left.insert(x);
                } else {
                    right.insert(x);
                }
            }
        }
        if (op == 2) {
            int y;
            cin >> y;
            int max_left = *left.rbegin();
            int next_max_left = max_left + y;
            if (next_max_left > *right.begin()) {
                left.erase(left.find(*left.rbegin()));
                left.insert(*right.begin());
                right.erase(right.find(*right.begin()));
                right.insert(next_max_left);
            } else {
                left.erase(left.find(*left.rbegin()));
                left.insert(next_max_left);
            }
        }
        if (op == 3) {
            cout << *left.rbegin() << '\n';
        }
    }
}
0