結果

問題 No.3298 K-th Slime
コンテスト
ユーザー syun0713
提出日時 2025-10-05 14:17:29
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 237 ms / 2,000 ms
+ 668µs
コード長 9,565 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,760 ms
コンパイル使用メモリ 294,404 KB
実行使用メモリ 23,104 KB
最終ジャッジ日時 2026-07-15 12:08:35
合計ジャッジ時間 6,322 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:71:21: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts' [-Wc++20-extensions]
   71 | void ain(set<T>& Y, auto n) {
      |                     ^~~~
main.cpp:78:26: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts' [-Wc++20-extensions]
   78 | void ain(multiset<T>& Y, auto n) {
      |                          ^~~~

ソースコード

diff #
raw source code

#pragma GCC target("arch=skylake-avx512")
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#ifdef ATCODER
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
#endif
#ifdef ONLINE_JUDGE
#else
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
#endif
using namespace std;
template<typename T>
using vec = vector<T>;
using ll = long long;
using ull = unsigned long long;
using vi = vec<int>;
using vs = vec<string>;
using si = set<int>;
using sll = set<ll>;
using vc = vec<char>;
using vvi = vec<vi>;
using vll = vec<ll>;
using vvll = vec<vll>;
using vsi = vec<si>;
using vsll = vec<sll>;
using vd = vec<double>;
using vvd = vec<vd>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using mii = map<int, int>;
using mll = map<ll, ll>;
using msi = map<string, int>;
using vpii = vec<pii>;
using vpll = vec<pll>;
using spii = set<pii>;
using spll = set<pll>;
using vb = vector<bool>;
using vvb = vector<vb>;
#define rep(i,j,n) for(ll i=j;i<n;i++)
#define rrep(i,j,n) for (ll i = n-1; i >=j; i--)
#define rp(i,n) rep(i,0,n)
#define rrp(i,n) rrep(i,0,n)
#define all(v) v.begin(), v.end()
#define pb push_back
#define ins insert
#define yes cout<<"Yes"<<endl;
#define no cout<<"No"<<endl; 
#define yn(jg) cout<<(jg? "Yes":"No")<<endl;
#define NL {cout<<endl;}
#define n0 {cout<<"-1"<<endl;}
#define lwb lower_bound
#define upb upper_bound
#define sz size()
#define fi first
#define se second
#define nxp next_permutation
ll mod0 = 998244353, lmax = 2e18, inf = 2e9;
double pi = 3.141592653589793238462643;
vll vh = { 998244353, 998244853, 1000000007, 1000000009, 1012924417 };
template<typename... T>
void in(T&... X) { (cin >> ... >> X); }
template<typename T>
void ain(vec<T>& Y) { rp(K, Y.size()) cin >> Y[K]; }
template<typename T>
void ain(set<T>& Y, auto n) {
	rp(i, n) {
		T YY; cin >> YY;
		Y.insert(YY);
	}
}
template<typename T>
void ain(multiset<T>& Y, auto n) {
	rp(i, n) {
		T YY; cin >> YY;
		Y.insert(YY);
	}
}
template<typename T>
void bin(vec<vec<T>>& Z) { rp(L, Z.size()) ain(Z[L]); }
template<typename T>
void aout(T& a) { for (auto I : a) cout << I << " "; cout << endl; }
void aout(pll a) { cout << a.fi << " " << a.se << endl; }
template<typename T>
void aout(queue<T> a) {
	while (!a.empty()) { cout << a.front(); a.pop(); }
}
template<typename T>
void aout(stack<T> a) {
	while (!a.empty()) { cout << a.top(); a.pop(); }
}
#define bout(a) {for(auto J:a) aout(J);}
template<typename T>
bool chmin(T& M1, T M2) {
	if (M1 > M2) { M1 = M2; return 1; }
	else return 0;
}
template<typename T>
bool chmax(T& M1, T M2) {
	if (M1 < M2) { M1 = M2; return 1; }
	else return 0;
}
template<typename T>
auto vmax(T& a) {
	return *max_element(all(a));
}
template<typename T>
auto vmin(T& a) {
	return *min_element(all(a));
}
vector<pair<char, ll>>  rle(string rr) {
	vector<pair<char, ll>> ret;
	char lc;
	rep(i, 0, rr.size()) {
		if (i > 0 && rr[i] == lc) ret[ret.sz - 1].second++;
		else { ret.pb({ rr[i],1 }); }
		lc = rr[i];
	}
	return ret;
}
vector<pair<int, ll>>  rle(vi rr) {
	vector<pair<int, ll>> ret;
	int lc;
	rep(i, 0, rr.size()) {
		if (i > 0 && rr[i] == lc) ret[ret.sz - 1].second++;
		else { ret.pb({ rr[i],1 }); }
		lc = rr[i];
	}
	return ret;
}
vector<pair<ll, ll>>  rle(vll rr) {
	vector<pair<ll, ll>> ret;
	ll lc;
	rep(i, 0, rr.size()) {
		if (i > 0 && rr[i] == lc) ret[ret.sz - 1].second++;
		else { ret.pb({ rr[i],1 }); }
		lc = rr[i];
	}
	return ret;
}
template<typename T>
auto lwa(vector<T>& a, T b) {//aでbより小さい最大の値のイテレータ(複数あれば右端)
	auto i = lwb(all(a), b);
	if (i == a.begin()) return a.end();
	else i--;
	return i;
}
template<typename T>
auto lwa(set<T>& a, T b) {//aでbより小さい最大の値のイテレータ
	auto i = a.lwb(b);
	if (i == a.begin()) return a.end();
	else i--;
	return i;
}
template<typename T>
auto lwa(multiset<T>& a, T b) {//aでbより小さい最大の値のイテレータ
	auto i = a.lwb(b);
	if (i == a.begin()) return a.end();
	else i--;
	return i;
}
template<typename T>
auto lwc(vector<T>& a, T b) {//aでb以下の最大の値のイテレータ(複数あれば左端)
	auto i = lwb(all(a), b);
	if (i != a.end() && *i == b) return i;
	if (i == a.begin()) return a.end();
	else i--;
	return i;
}
template<typename T>
auto lwc(set<T>& a, T b) {//aでb以下の最大の値のイテレータ
	auto i = a.lwb(b);
	if (i != a.end() && *i == b) return i;
	if (i == a.begin()) return a.end();
	else i--;
	return i;
}
template<typename T>
auto lwc(multiset<T>& a, T b) {//aでb以下の最大の値のイテレータ
	auto i = a.lwb(b);
	if (i != a.end() && *i == b) return i;
	if (i == a.begin()) return a.end();
	else i--;
	return i;
}

template<typename T>
vec<T> rsw(vec<T>& a) {//累積和
	vec<T> b = a;
	rep(i, 1, b.size()) b[i] += b[i - 1];
	return b;
}
bool kai(string S) {//回文か判定
	bool ans = 1;
	rp(i, S.size()) if (S[i] != S[S.size() - 1 - i]) ans = 0;
	return ans;
}


sll yk(ll n) {//約数全列挙O(sqrt(N)),set<int>
	sll yaku;
	for (ll i = 1; i * i <= n; i++) if (n % i == 0) {
		yaku.insert(i);
		yaku.insert(n / i);
	}
	return yaku;
}
vi ssa(int n) {//n:必要な素数の最大値 素数全列挙
	vector<int> prime;
	vector<int>lpf(n + 1, 0);
	rep(i, 2, n + 1) {
		if (lpf[i] == 0) {
			lpf[i] = i;
			prime.push_back(i);
		}
		for (int k : prime) {
			if (k * i > n || k > lpf[i]) break;//k最小素因数よりk<=i
			lpf[k * i] = k;//kを最小素因数に持つ数k*iを拾う
		}
	}
	return prime;
}
vector<pll> sib(ll x) {//素因数分解
	if (x == 1) return vector<pll>(1, { 1,1 });
	vector<pll> ans;
	for (ll i = 2; i * i <= x; i++) {//rootx回iを回しxで割る
		ll kaisu = 0;
		while (x % i == 0) {
			x /= i; kaisu++;
		}
		if (kaisu > 0) ans.pb({ i,kaisu });
	}
	if (x != 1) ans.pb({ x,1 });
	return ans;
}
template<typename T>
vec<T> zat(vec<T> a) {//座標圧縮
	auto b = a;
	sort(all(b));
	b.erase(unique(all(b)), b.end());
	vec<T> c(a.size());
	rp(i, a.size()) {
		c[i] = lwb(all(b), a[i]) - b.begin();
	}
	return c;
}
template<typename T>
void cp(map < T, ll >& a, T b, ll c) {//countplus
	if (a.find(b) == a.end()) a[b] = c;
	else a[b] += c;
	if (a[b] == 0) a.erase(b);
}
template<typename T>
vec<T> inv(vec<T> a) {//0-indexed 逆関数(1-indexedは全要素--)
	vec<T> ans(a.sz);
	rp(i, a.sz) {
		ans[a[i]] = i;
	}
	return ans;
}
vll hs(string s) {//hash
	vll r = { 0,0,0,0,0 };
	rp(i, 5) {
		rp(j, s.sz) {
			r[i] *= 27;
			r[i] += (s[j] - 'a' + 1);
			r[i] %= vh[i];
		}
	}
	return r;
}
vll hsp(ll n) {//hashpow
	vll r = { 1,1,1,1,1 };
	rp(i, 5) {
		rp(j, n) {
			r[i] *= 27;
			r[i] %= vh[i];
		}
	}
	return r;
}
template<typename T>
bool cross(T a, T b, T c, T d) {//区間(a,b)と区間(c,d)が重なるか判定
	return !(b <= c || d <= a);
}
template<typename T>
bool crosse(T a, T b, T c, T d) {//区間[a,b]と区間[c,d]が重なるか判定
	return !(b < c || d < a);
}
ll llpow(ll x, ll y) {
	ll xx = 1;
	while (y--) {
		assert(double(lmax) / x > xx);
		xx *= x;
	}
	return xx;
}
//lazy_segtree<S, op, e, F, mapping, composition, id> seg(n);
//S:中身型 op:左右合成 e:初期値
//F:遅延型 mapping:遅延適用後の要素 composition:遅延合成( 関数f(g()) ) id:遅延初期値(何もさせない)
/*
using S = double;
using F = int;
S op(S a,S b) {
	return min(a, b);
}

S e() {
	return lmax;
}
S mapping(F x, S a) {//xをaに作用(x初期値に注意)
	if (x != 0)return x;
	else return a;
}
F composition(F f, F g) {//fの方が後(f初期値に注意)
	if (f != 0)return f;
	else return g;
}
F id() {return 0;}*/
//cout<<setprecision(15)<<fixed<<
//function<返り値の型(引数の型1, 引数の型2, ...)> 関数名 = [&](引数の型1 引数名1, 引数の型2, 引数名2, ...) 
template<typename T1,typename T2>//keyの型、値の型
struct topk {
	multiset<pair<T2,T1>> top;
	multiset<pair<T2, T1>> bot;//昇順の時はgreaterを消す
	map<T1,T2> ktov;
	int k = 0;
	ll tsum = 0, asum = 0;
	void ar(){//個数整理
		while (top.size() > k) {
			auto it = top.end(); it--;
			bot.insert(*it);
			tsum -= it->fi;
			top.erase(it);
		}
		while (top.size() < k && bot.size()!=0) {
			auto it = bot.begin();
			top.insert(*it);
			tsum += it->fi;
			bot.erase(it);
		}
	}
	void set(int newk) {//最初に必ず呼ぶ
		k = newk;
		ar();
	}
	void erase(T1 a) {
		if (ktov.find(a) != ktov.end()) {
			auto b = ktov[a];
			if (top.find({b,a }) != top.end()) {
				tsum -= b; asum -= b;
				top.erase({b,a });
				ar();
			}
			else if (bot.find({b,a }) != bot.end()) {
				asum -= b;
				bot.erase({b,a });
				ar();
			}
			ktov.erase(a);
		}
	}
	void insert(T1 a,T2 b) {//兼update
		erase(a);
		ktov[a] = b;
		if (top.sz != 0 && (--top.end())->fi > b) {//昇順の時は>
			top.insert({ b,a });
			asum += b; tsum += b;
		}
		else {
			bot.insert({ b,a });
			asum += b;
		}
		ar();
	}
	void insert(pair<T1, T2> a) {
		insert(a.fi, a.se);
	}
	int bsum() {
		return asum - tsum;

	}	
	auto find(T1 a) {
		return ktov.find(a);
	}
	T2 operator[](T1 a){
		return ktov[a];
	}
};
int main() {
	int n, k, q;
	cin >> n >> k >> q;
	vll a(n); ain(a);
	topk<ll,ll> r;
	r.set(k);
	rp(i,n)r.insert(i, a[i]);
	while (q--) {
		ll x;
		cin >> x;
		if (x == 1) {
			ll y;
			cin >> y;
			a.pb(y);
			r.insert(ll(a.sz) - 1, y);
		}
		if (x == 2) {
			ll y; cin >> y;
			auto it=r.top.end();
			it--;
			y += it->first;
			ll b = it->second;
			r.erase(b);
			r.insert(b, y);
		}
		if (x == 3) {
			auto it = r.top.end();
			it--;
			cout << it->first << endl;
		}
	}
}
0