結果
問題 | No.649 ここでちょっとQK! |
ユーザー | Pachicobue |
提出日時 | 2018-02-11 19:10:59 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 258 ms / 3,000 ms |
コード長 | 4,292 bytes |
コンパイル時間 | 2,594 ms |
コンパイル使用メモリ | 217,628 KB |
実行使用メモリ | 24,092 KB |
最終ジャッジ日時 | 2024-11-17 12:45:26 |
合計ジャッジ時間 | 8,810 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 258 ms
6,400 KB |
testcase_04 | AC | 148 ms
24,092 KB |
testcase_05 | AC | 145 ms
23,964 KB |
testcase_06 | AC | 58 ms
9,500 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 2 ms
5,248 KB |
testcase_10 | AC | 2 ms
5,248 KB |
testcase_11 | AC | 2 ms
5,248 KB |
testcase_12 | AC | 115 ms
12,800 KB |
testcase_13 | AC | 99 ms
12,928 KB |
testcase_14 | AC | 97 ms
12,800 KB |
testcase_15 | AC | 97 ms
12,928 KB |
testcase_16 | AC | 96 ms
12,924 KB |
testcase_17 | AC | 115 ms
13,724 KB |
testcase_18 | AC | 121 ms
14,648 KB |
testcase_19 | AC | 138 ms
15,316 KB |
testcase_20 | AC | 150 ms
16,240 KB |
testcase_21 | AC | 165 ms
18,056 KB |
testcase_22 | AC | 180 ms
18,992 KB |
testcase_23 | AC | 188 ms
19,968 KB |
testcase_24 | AC | 192 ms
20,836 KB |
testcase_25 | AC | 207 ms
21,628 KB |
testcase_26 | AC | 213 ms
22,428 KB |
testcase_27 | AC | 2 ms
5,248 KB |
testcase_28 | AC | 2 ms
5,248 KB |
testcase_29 | AC | 2 ms
5,248 KB |
testcase_30 | AC | 74 ms
10,492 KB |
testcase_31 | AC | 74 ms
10,492 KB |
testcase_32 | AC | 2 ms
5,248 KB |
testcase_33 | AC | 2 ms
5,248 KB |
testcase_34 | AC | 2 ms
5,248 KB |
testcase_35 | AC | 2 ms
5,248 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; template <typename Base> class BinaryIndexedTree { public: using T = typename Base::T; using AbelGroup = Base; BinaryIndexedTree(const int n) : data_num(n), size(1 << (__lg(2 * data_num - 1))), value(size + 1, AbelGroup::identity()) { assert(n > 0); } BinaryIndexedTree(const vector<T>& val) : data_num(val.size()), size(1 << (__lg(2 * data_num - 1))), value(size + 1, AbelGroup::identity()) { for (int i = 1; i <= data_num; i++) { value[i] = val[i - 1]; } for (int x = 1; x < size; x++) { value[x + (x & -x)] = op(value[x + (x & -x)], value[x]); } } T accumulate(const int a) const { assert(0 <= a and a < data_num); int ind = a + 1; T sum = AbelGroup::identity(); while (ind > 0) { sum = op(sum, value[ind]); ind &= ind - 1; } return sum; } T accumulate(const int l, const int r) const // [l,r) { assert(0 <= l and l < r and r <= data_num); return op(accumulate(r - 1), op.inv(l == 0 ? AbelGroup::identity() : accumulate(l - 1))); } void add(const int a, const T& val) { assert(0 <= a and a < data_num); int ind = a + 1; while (ind <= size) { value[ind] = op(value[ind], val); ind += ind & (-ind); } } void set(const int a, const T& val) { const int v = get(a); add(a, op(val, op.inv(v))); } T get(const int a) const { assert(0 <= a and a < data_num); return accumulate(a, a + 1); } int lowerBound(T w) const { if (w <= AbelGroup::identity()) { return 0; } int x = 0; for (int k = ((size == data_num) ? size : size / 2); k > 0; k /= 2) { if (x + k <= size and value[x + k] < w) { w = op(w, op.inv(value[x + k])); x += k; } } return x; } int upperBound(T w) const { if (w <= AbelGroup::identity()) { return 0; } int x = 0; for (int k = ((size == data_num) ? size : size / 2); k > 0; k /= 2) { if (x + k <= size and value[x + k] <= w) { w = op(w, op.inv(value[x + k])); x += k; } } return min(x, data_num); } private: const int data_num; const int size; const AbelGroup op{}; vector<T> value; }; template <typename T> ostream& operator<<(ostream& os, const BinaryIndexedTree<T>& bit) { os << "["; for (int i = 0; i < bit.data_num; i++) { os << bit.get(i) << ","; } os << "]" << endl; return os; } struct Sum { using T = ll; T operator()(const T& a, const T& b) const { return a + b; } T inv(const T& a) const { return -a; } static constexpr T identity() { return 0; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); int Q, K; cin >> Q >> K; using P = pair<int, ll>; vector<P> query(Q); vector<ll> v; for (int q = 0; q < Q; q++) { cin >> query[q].first; if (query[q].first == 1) { cin >> query[q].second; v.push_back(query[q].second); } } auto zip = v; sort(zip.begin(), zip.end()); zip.erase(unique(zip.begin(), zip.end()), zip.end()); map<ll, int> mp; const int size = zip.size(); if (size != 0) { for (int i = 0; i < zip.size(); i++) { mp[zip[i]] = i; } BinaryIndexedTree<Sum> bit(size); for (int q = 0; q < Q; q++) { if (query[q].first == 1) { const int t = mp[query[q].second]; bit.add(t, 1); } else { if (bit.accumulate(size - 1) < K) { cout << -1 << "\n"; } else { const int l = bit.lowerBound(K); cout << zip[l] << "\n"; bit.add(l, -1); } } } } else { for (int q = 0; q < Q; q++) { cout << -1 << endl; } } return 0; }