結果
| 問題 |
No.649 ここでちょっとQK!
|
| コンテスト | |
| ユーザー |
hashiryo
|
| 提出日時 | 2020-04-28 23:49:15 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 262 ms / 3,000 ms |
| コード長 | 1,863 bytes |
| コンパイル時間 | 1,859 ms |
| コンパイル使用メモリ | 174,672 KB |
| 実行使用メモリ | 8,132 KB |
| 最終ジャッジ日時 | 2024-11-26 01:18:23 |
| 合計ジャッジ時間 | 6,835 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n) \
for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
struct BinaryIndexedTree {
vector<long long> dat;
BinaryIndexedTree(int n) : dat(n + 1, 0) {}
BinaryIndexedTree(int n, long long a)
: BinaryIndexedTree(vector<long long>(n, a)) {}
BinaryIndexedTree(vector<long long> y) : dat(y.size() + 1) {
for (int k = 0; k < y.size(); ++k) dat[k + 1] = y[k];
for (int k = 1; k + (k & -k) < dat.size(); ++k) dat[k + (k & -k)] += dat[k];
}
void add(int k, long long a) {
for (++k; k < dat.size(); k += k & -k) dat[k] += a;
}
// sum [0,k)
long long operator[](int k) {
long long s = 0;
for (; k > 0; k &= k - 1) s += dat[k];
return s;
}
// min{ k : sum(k) >= a }
int lower_bound(long long a) const {
int k = 0;
for (int p = 1 << (__lg(dat.size() - 1) + 1); p > 0; p >>= 1)
if (k + p < dat.size() && dat[k + p] < a) a -= dat[k += p];
return k + 1 == dat.size() ? -1 : k;
}
};
signed main() {
cin.tie(0);
ios::sync_with_stdio(0);
int Q, K;
cin >> Q >> K;
vector<long long> query;
vector<long long> x;
while (Q--) {
long long v;
cin >> v;
if (v == 1) {
cin >> v;
x.push_back(v);
} else {
v = -1;
}
query.push_back(v);
}
sort(x.begin(), x.end());
x.erase(unique(x.begin(), x.end()), x.end());
BinaryIndexedTree bit(x.size());
for (auto q : query) {
if (q < 0) {
int i = bit.lower_bound(K);
if (i >= 0) {
cout << x[i] << endl;
bit.add(i, -1);
} else {
cout << -1 << endl;
}
} else {
int i = lower_bound(x.begin(), x.end(), q) - x.begin();
bit.add(i, 1);
}
}
}
hashiryo