結果
問題 | No.649 ここでちょっとQK! |
ユーザー | tsuyu93 |
提出日時 | 2020-12-08 00:47:05 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 292 ms / 3,000 ms |
コード長 | 9,507 bytes |
コンパイル時間 | 2,554 ms |
コンパイル使用メモリ | 192,388 KB |
実行使用メモリ | 12,928 KB |
最終ジャッジ日時 | 2024-09-17 14:13:49 |
合計ジャッジ時間 | 7,649 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 251 ms
6,940 KB |
testcase_04 | AC | 86 ms
12,928 KB |
testcase_05 | AC | 90 ms
12,800 KB |
testcase_06 | AC | 88 ms
12,928 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 123 ms
7,680 KB |
testcase_13 | AC | 120 ms
7,680 KB |
testcase_14 | AC | 128 ms
7,680 KB |
testcase_15 | AC | 131 ms
7,680 KB |
testcase_16 | AC | 120 ms
7,680 KB |
testcase_17 | AC | 142 ms
8,192 KB |
testcase_18 | AC | 154 ms
8,448 KB |
testcase_19 | AC | 169 ms
8,832 KB |
testcase_20 | AC | 186 ms
9,344 KB |
testcase_21 | AC | 206 ms
9,728 KB |
testcase_22 | AC | 234 ms
10,240 KB |
testcase_23 | AC | 247 ms
10,624 KB |
testcase_24 | AC | 261 ms
11,136 KB |
testcase_25 | AC | 282 ms
11,392 KB |
testcase_26 | AC | 292 ms
11,904 KB |
testcase_27 | AC | 2 ms
6,944 KB |
testcase_28 | AC | 2 ms
6,940 KB |
testcase_29 | AC | 3 ms
6,940 KB |
testcase_30 | AC | 120 ms
7,552 KB |
testcase_31 | AC | 123 ms
7,552 KB |
testcase_32 | AC | 2 ms
6,940 KB |
testcase_33 | AC | 1 ms
6,944 KB |
testcase_34 | AC | 2 ms
6,940 KB |
testcase_35 | AC | 2 ms
6,948 KB |
ソースコード
/* author:ryo3ihara ”継続は力なり、雨だれ石を穿つ” ”slow but steady wins the race” */ #pragma GCC optimize("Ofast") #include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; /* // 多倍長テンプレ #include <boost/multiprecision/cpp_dec_float.hpp> #include <boost/multiprecision/cpp_int.hpp> namespace mp = boost::multiprecision; // 任意長整数型 using Bint = mp::cpp_int; // 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする) using Real = mp::number<mp::cpp_dec_float<1024>>; */ using namespace std; using ll = long long; using ld = long double; using pll = pair<ll, ll>; using pli = pair<ll, int>; using pii = pair<int, int>; using pld = pair<ll, ld>; using ppiii = pair<pii, int>; using ppiill = pair<pii, ll>; using ppllll = pair<pll, ll>; using pplii = pair<pli, int>; using mii = map<int, int>; using dll = deque<ll>; using qll = queue<ll>; using pqll = priority_queue<ll>; using pqrll = priority_queue<ll, vector<ll>, greater<ll>>; using vint = vector<int>; using vll = vector<ll>; using vpll = vector<pll>; using vvll = vector<vector<ll>>; using vvint = vector<vector<int>>; using vvpll = vector<vector<pll>>; //マクロ //forループ #define REP(i,n) for(ll i=0;i<ll(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=ll(b);i++) #define FORD(i,a,b) for(ll i=a;i>=ll(b);i--) #define ALL(x) x.begin(),x.end() #define rALL(x) x.rbegin(),x.rend() #define SIZE(x) ll(x.size()) #define fs first #define sc second #define INF32 2147483647 //2.147483647x10^{9}:32bit整数のinf #define INF64 9223372036854775807 //9.223372036854775807x10^{18}:64bit整数のinf //定数 const ll MOD = 1000000007; const int inf = 1e9; const ll INF = 1e18; const ll MAXR = 100000; //10^5:配列の最大のrange inline void Yes(bool b = true) { cout << (b ? "Yes" : "No") << '\n'; } inline void YES(bool b = true) { cout << (b ? "YES" : "NO") << '\n'; } //最大化問題最小化問題 template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } //高速冪乗化 modの時は一部入れ替える ll power(ll a, ll b) { ll res=1; while (b>0) { if (b&1){ res*=a; //res%=MOD; } b/=2; a*=a; //a%=MOD; } return res; } ll power2(ll x, ll y) { if(y == 0) return 1; if(y == 1) { return x; // return x % MOD; } ll ans; if(y % 2 == 1) { ll r = power(x,(y-1)/2); //ans = r * r % MOD; //ans = ans * x % MOD; ans = x * r * r; } else { ll r = power(x,y/2); //ans = r * r % MOD; ans = r * r; } return ans; } /* Bint powerb(Bint x, Bint y) { if(y == 0) return 1; if(y == 1) { return x; // return x % MOD; } Bint ans; if(y % 2 == 1) { Bint r = powerb(x,(y-1)/2); //ans = r * r % MOD; //ans = ans * x % MOD; ans = x * r * r; } else { Bint r = powerb(x,y/2); //ans = r * r % MOD; ans = r * r; } return ans; } */ template<class VAL> struct RBST { VAL SUM_UNITY = 0; // to be set unsigned int randInt() { static unsigned int tx = 123456789, ty = 362436069, tz = 521288629, tw = 88675123; unsigned int tt = (tx ^ (tx << 11)); tx = ty; ty = tz; tz = tw; return (tw = (tw ^ (tw >> 19)) ^ (tt ^ (tt >> 8))); } struct NODE { NODE *left, *right; VAL val; // the value of the node int size; // the size of the subtree VAL sum; // the value-sum of the subtree NODE() : val(SUM_UNITY), size(1), sum(SUM_UNITY) { left = right = NULL; } NODE(VAL v) : val(v), size(1), sum(v) { left = right = NULL; } /* additional update */ inline void update() { } /* additional lazy-propagation */ inline void push() { /* ex: reverse */ /* if (this->rev) { swap(this->left, this->right); if (this->left) this->left->rev ^= true; if (this->right) this->right->rev ^= true; this->rev = false; } */ } }; /////////////////////// // root /////////////////////// NODE* root; RBST() : root(NULL) { } RBST(NODE* node) : root(node) { } /////////////////////// // basic operations /////////////////////// /* size */ inline int size(NODE *node) { return !node ? 0 : node->size; } inline int size() { return this->size(this->root); } /* sum */ inline VAL sum(NODE *node) { return !node ? SUM_UNITY : node->sum; } inline VAL sum() { return this->sum(this->root); } /* update, push */ inline NODE* update(NODE *node) { node->size = size(node->left) + size(node->right) + 1; node->sum = sum(node->left) + sum(node->right) + node->val; node->update(); return node; } inline void push(NODE *node) { if (!node) return; node->push(); } /* lower_bound */ inline int lowerBound(NODE *node, VAL val) { push(node); if (!node) return 0; if (val <= node->val) return lowerBound(node->left, val); else return size(node->left) + lowerBound(node->right, val) + 1; } inline int lowerBound(VAL val) { return this->lowerBound(this->root, val); } /* upper_bound */ inline int upperBound(NODE *node, VAL val) { push(node); if (!node) return 0; if (val >= node->val) return size(node->left) + upperBound(node->right, val) + 1; else return upperBound(node->left, val); } inline int upperBound(VAL val) { return this->upperBound(this->root, val); } /* count */ inline int count(VAL val) { return upperBound(val) - lowerBound(val); } /* get --- k: 0-index */ inline VAL get(NODE *node, int k) { push(node); if (!node) return -1; if (k == size(node->left)) return node->val; if (k < size(node->left)) return get(node->left, k); else return get(node->right, k - size(node->left) - 1); } inline VAL get(int k) { return get(this->root, k); } /////////////////////// // merge-split /////////////////////// NODE* merge(NODE *left, NODE *right) { push(left); push(right); if (!left || !right) { if (left) return left; else return right; } if (randInt() % (left->size + right->size) < left->size) { left->right = merge(left->right, right); return update(left); } else { right->left = merge(left, right->left); return update(right); } } void merge(RBST add) { this->root = this->merge(this->root, add.root); } pair<NODE*, NODE*> split(NODE* node, int k) { // [0, k), [k, n) push(node); if (!node) return make_pair(node, node); if (k <= size(node->left)) { pair<NODE*, NODE*> sub = split(node->left, k); node->left = sub.second; return make_pair(sub.first, update(node)); } else { pair<NODE*, NODE*> sub = split(node->right, k - size(node->left) - 1); node->right = sub.first; return make_pair(update(node), sub.second); } } RBST split(int k) { pair<NODE*, NODE*> sub = split(this->root, k); this->root = sub.first; return RBST(sub.second); } /////////////////////// // insert-erase /////////////////////// void insert(const VAL val) { pair<NODE*, NODE*> sub = this->split(this->root, this->lowerBound(val)); this->root = this->merge(this->merge(sub.first, new NODE(val)), sub.second); } void erase(const VAL val) { if (!this->count(val)) return; pair<NODE*, NODE*> sub = this->split(this->root, this->lowerBound(val)); this->root = this->merge(sub.first, this->split(sub.second, 1).second); } /////////////////////// // debug /////////////////////// void print(NODE *node) { if (!node) return; push(node); print(node->left); cout << node->val << " "; print(node->right); } void print() { cout << "{"; print(this->root); cout << "}" << endl; } }; signed main(){ //入力の高速化用のコード ios::sync_with_stdio(false); cin.tie(nullptr); //入力 RBST<ll> S; ll Q,K; cin >> Q >> K; REP(_,Q){ int T; cin >> T; if(T==1){ ll val; cin >> val; S.insert(val); } else{ if(S.size()<K){ cout << -1 << endl; continue; } ll res = S.get(K-1); cout << res << endl; S.erase(res); } } return 0; }