結果
問題 | No.649 ここでちょっとQK! |
ユーザー | i_am_nicolen_22 |
提出日時 | 2020-06-01 19:41:56 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 760 ms / 3,000 ms |
コード長 | 3,709 bytes |
コンパイル時間 | 2,209 ms |
コンパイル使用メモリ | 180,576 KB |
実行使用メモリ | 20,572 KB |
最終ジャッジ日時 | 2024-11-22 06:35:03 |
合計ジャッジ時間 | 16,035 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
5,248 KB |
testcase_01 | AC | 3 ms
5,248 KB |
testcase_02 | AC | 3 ms
5,248 KB |
testcase_03 | AC | 304 ms
8,064 KB |
testcase_04 | AC | 760 ms
20,572 KB |
testcase_05 | AC | 755 ms
20,444 KB |
testcase_06 | AC | 188 ms
9,732 KB |
testcase_07 | AC | 3 ms
5,248 KB |
testcase_08 | AC | 3 ms
5,248 KB |
testcase_09 | AC | 3 ms
5,248 KB |
testcase_10 | AC | 3 ms
5,248 KB |
testcase_11 | AC | 3 ms
5,248 KB |
testcase_12 | AC | 370 ms
12,012 KB |
testcase_13 | AC | 368 ms
12,012 KB |
testcase_14 | AC | 364 ms
11,996 KB |
testcase_15 | AC | 362 ms
12,024 KB |
testcase_16 | AC | 361 ms
12,152 KB |
testcase_17 | AC | 411 ms
12,852 KB |
testcase_18 | AC | 447 ms
13,580 KB |
testcase_19 | AC | 475 ms
14,276 KB |
testcase_20 | AC | 521 ms
15,012 KB |
testcase_21 | AC | 563 ms
15,592 KB |
testcase_22 | AC | 575 ms
16,448 KB |
testcase_23 | AC | 607 ms
17,044 KB |
testcase_24 | AC | 655 ms
17,888 KB |
testcase_25 | AC | 698 ms
18,616 KB |
testcase_26 | AC | 737 ms
19,316 KB |
testcase_27 | AC | 6 ms
5,248 KB |
testcase_28 | AC | 6 ms
5,248 KB |
testcase_29 | AC | 6 ms
5,248 KB |
testcase_30 | AC | 244 ms
10,736 KB |
testcase_31 | AC | 246 ms
10,732 KB |
testcase_32 | AC | 3 ms
5,248 KB |
testcase_33 | AC | 3 ms
5,248 KB |
testcase_34 | AC | 3 ms
5,248 KB |
testcase_35 | AC | 3 ms
5,248 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define REP(i, s) for (int i = 0; i < s; ++i) #define ALL(v) (v).begin(), (v).end() #define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl #define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i) #define DEBUG #define int long long #define INF 1e18 template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) { return s << '<' << P.first << ", " << P.second << '>'; } template<class T> ostream& operator << (ostream &s, vector<T> P) { for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; } template<class T> ostream& operator << (ostream &s, vector<vector<T> > P) { for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; } template<class T> ostream& operator << (ostream &s, set<T> P) { EACH(it, P) { s << "<" << *it << "> "; } return s << endl; } template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) { EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; } template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";} typedef long long ll; template <class Abel> struct BIT { vector<Abel> dat; Abel UNITY_SUM = 0; // to be set /* [1, n] */ BIT(int n) { init(n); } void init(int n) { dat.resize(n + 1); for (int i = 0; i < (int)dat.size(); ++i) dat[i] = UNITY_SUM; } /* a is 1-indexed */ inline void add(int a, Abel x) { for (int i = a; i < (int)dat.size(); i += i & -i) dat[i] = dat[i] + x; } /* [1, a], a is 1-indexed */ inline Abel sum(int a) { Abel res = UNITY_SUM; for (int i = a; i > 0; i -= i & -i) res = res + dat[i]; return res; } /* [a, b), a and b are 1-indexed */ inline Abel sum(int a, int b) { return sum(b - 1) - sum(a - 1); } /* k-th number (k is 0-indexed) */ int get(long long k) { ++k; int res = 0; int N = 1; while (N < (int)dat.size()) N *= 2; for (int i = N / 2; i > 0; i /= 2) { if (res + i < (int)dat.size() && dat[res + i] < k) { k = k - dat[res + i]; res = res + i; } } return res + 1; } }; signed main() { int q, k; cin >> q >> k; vector<int> type(q); vector<int> ad; vector<int> V(q); for (int i = 0; i < q; i++) { int x; cin >> x; if(x==1){ int u; cin >> u; type[i] = x; V[i] = u; ad.push_back(u); } else{ type[i] = x; } } sort(ad.begin(), ad.end()); set<int> st(ad.begin(), ad.end()); vector<int> v(st.begin(), st.end()); show(v); BIT<int> bit(200010); for (int i = 0; i < q; i++) { if(type[i]==1){ int idx = lower_bound(ALL(v), V[i]) - v.begin(); //cerr << idx << endl; idx++; bit.add(idx, 1); } else{ int size = bit.sum(200010); if(k>size){ cout << -1 << endl; } else{ int id = bit.get(k - 1); //cerr << "id" << id << endl; cout << v[id - 1] << endl; bit.add(id, -1); } } } return 0; }