結果

問題 No.3298 K-th Slime
ユーザー AD010
提出日時 2025-10-05 14:29:18
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 4,750 bytes
コンパイル時間 3,216 ms
コンパイル使用メモリ 286,540 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2025-10-05 14:29:49
合計ジャッジ時間 4,992 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define ll long long
#define ull unsigned long long
#define ld  long double

using LL = long long; using ULL = unsigned long long;
using VI = vector<int>; using VVI = vector<VI>; using VVVI = vector<VVI>;
using VL = vector<LL>; using VVL = vector<VL>; using VVVL = vector<VVL>;
using VB = vector<bool>; using VVB = vector<VB>; using VVVB = vector<VVB>;
using VD = vector<double>; using VVD = vector<VD>; using VVVD = vector<VVD>;
using VC = vector<char>; using VS = vector<string>; using VVC = vector<VC>;
using PII = pair<int,int>; using PLL = pair<LL,LL>; using PDD = pair<double,double>; using PIL = pair<int,LL>;
using MII = map<int,int>; using MLL = map<LL,LL>;
using SI = set<int>; using SL = set<LL>;
using MSI = multiset<int>; using MSL = multiset<LL>;
template<class T> using MAXPQ = priority_queue<T>;
template<class T> using MINPQ = priority_queue< T, vector<T>, greater<T> >;

const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll INF = 1LL << 60;
#define PI  3.14159265358979323846

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EACH(e, v) for(auto &e : v)
#define RITR(it, v) for(auto it = (v).rbegin(); it != (v).rend(); ++it)
#define ALL(v) v.begin(),v.end()

vector<ll> x8={1,1,1,0,0,-1,-1,-1},y8={1,0,-1,1,-1,1,0,-1};
int dx4[4]={1,-1,0,0}, dy4[4]={0,0,1,-1};

/*
memo
-uf,RMQ(segtree),BIT,BIT2,SegTree,SegTreeLazy
-isprime,Eratosthenes,gcdlcm,factorize,divisors,modpow,moddiv
nCr(+modnCr,inverse,extend_euclid.powmod),tobaseB,tobase10
-dijkstra,Floyd,bellmanford,sccd,topological,treediamiter
-compress1,compress2,rotate90

-co,ci,fo1,fo2,fo3,fo4
-bitsearch,binaryserach
-bfs
-SegTreedec,SegTreeLazydec
*/

template<class T>
class BIT{
public:
    long long n;
    vector<T> a;

    //要素数n(1-indexed)
    BIT(long long _n){
        init(_n);
    }

    void init(long long _n){
        n = _n;
        a.assign(n+1,0);
    }

    //a[i]にxを加算(1-indexed)
    void add(long long i, long long x){
        if(i == 0) return;
        for(long long j = i; j <= n; j += (j & -j)){
            a[j] += x;
        }
    }

    //a[1]+a[2]+...a[r]を求める(1-indexed)
    T sum(long long r){
        return sum_sub(r);
    }
    
    //a[l]+a[l+1]+...a[r]を求める(1-indexed)
    T sum(long long l, long long r){
        return sum_sub(r) - sum_sub(l-1);
    }

    T sum_sub(long long r){
        long long s = 0;
        for(ll j = r; j > 0; j -= (j & -j)){
            s += a[j];
        }
        return s;
    }

    //a[1]+a[2]+...a[i] >= xとなる最小のiを求める(任意のkでa[k]>=0)
    long long lower_bound(long long x){
        if(x <= 0) return 0;
        else{
            long long i = 0, r = 1; //最初は0~rまで(左側から)
            while(r < n) r = r << 1; //長さ最大になるまで

            for(long long len = r; len > 0; len = len >> 1){ //1段下る
                if(i+len < n && a[i+len] < x){ //区間を採用
                    x -= a[i+len];
                    i += len; //右側へ
                }
            }

            return i+1;
        }
    }
};

template<typename T>
struct Compressor{
    vector<T> value;
    vector<int> comp;
    Compressor(vector<T> &dat): value(dat){
        comp.resize(dat.size());
        sort(value.begin(),value.end());
        value.erase(unique(value.begin(),value.end()),value.end());
        for(int i = 0; i < comp.size(); i++) comp[i] = lower_bound(value.begin(),value.end(),dat[i]) - value.begin();
    };    
 
    //value -> index
    int getindex(T val){
        auto it = lower_bound(value.begin(),value.end());
        assert(it != value.end() and *it == val);
        return it - value.begin();
    }
 
    //index -> value
    T getvalue(int idx){
        return value[idx];
    }
 
    //get compressed array;
    vector<int> get_comparray(){
        return comp;
    }
    
    int size(){
        return value.size();
    }
};


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    ll N,K,Q; cin >> N >> K >> Q;
    VL a(N); for(ll i = 0; i < N; i++) cin >> a[i];
    sort(ALL(a));
    ll tar = a[K-1];
    multiset<ll> st;
    for(ll i = 0; i < N; i++) st.insert(a[i]);

    while(Q--){
        int t; cin >> t;
        if(t==1){
            ll x; cin >> x;
            st.insert(x);
            auto it = st.lower_bound(tar);
            if(tar <= x) ;
            else it--;
            tar = *it;
        }
        if(t==2){
            ll y; cin >> y;
            st.insert(tar+y);
            auto it = st.lower_bound(tar);
            it++;
            st.erase(st.find(tar));
            tar = *it;
        }
        if(t==3){
            cout << tar << '\n';
        }
    }

    
    
}
0