結果
| 問題 |
No.649 ここでちょっとQK!
|
| コンテスト | |
| ユーザー |
rokahikou1
|
| 提出日時 | 2021-02-26 16:47:26 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 271 ms / 3,000 ms |
| コード長 | 5,295 bytes |
| コンパイル時間 | 1,647 ms |
| コンパイル使用メモリ | 178,748 KB |
| 実行使用メモリ | 11,192 KB |
| 最終ジャッジ日時 | 2024-10-02 09:05:16 |
| 合計ジャッジ時間 | 5,303 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:166:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
166 | for(auto [a, v] : query) {
| ^
ソースコード
#include <bits/stdc++.h>
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define ALL(v) (v).begin(), (v).end()
#define LLA(v) (v).rbegin(), (v).rend()
#define SZ(v) (v).size()
#define INT(...) \
int __VA_ARGS__; \
read(__VA_ARGS__)
#define LL(...) \
ll __VA_ARGS__; \
read(__VA_ARGS__)
#define DOUBLE(...) \
double __VA_ARGS__; \
read(__VA_ARGS__)
#define CHAR(...) \
char __VA_ARGS__; \
read(__VA_ARGS__)
#define STRING(...) \
string __VA_ARGS__; \
read(__VA_ARGS__)
#define VEC(type, name, size) \
vector<type> name(size); \
read(name)
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
template <typename T> struct edge {
int to;
T cost;
edge(int t, T c) : to(t), cost(c) {}
};
template <typename T> using WGraph = vector<vector<edge<T>>>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;
template <class T> inline vector<T> make_vec(size_t a, T val) {
return vector<T>(a, val);
}
template <class... Ts> inline auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec(ts...))>(a, make_vec(ts...));
}
void read() {}
template <class T> inline void read(T &a) { cin >> a; }
template <class T, class S> inline void read(pair<T, S> &p) {
read(p.first), read(p.second);
}
template <class T> inline void read(vector<T> &v) {
for(auto &a : v)
read(a);
}
template <class Head, class... Tail>
inline void read(Head &head, Tail &...tail) {
read(head), read(tail...);
}
template <class T> inline void chmax(T &a, T b) { (a < b ? a = b : a); }
template <class T> inline void chmin(T &a, T b) { (a > b ? a = b : a); }
/**
* @brief 0-indexed (Internally 1-indexed) Fenwick Tree
*
* @tparam T Universal set.
*/
template <typename T> struct FenwickTree {
int n;
vector<T> dat;
FenwickTree(int n) : n(++n), dat(n, 0) {}
void add(int i, T x) {
for(++i; i < n; i += i & -i)
dat[i] = dat[i] + x;
}
/**
* @brief Sum values in [0,i]
*
* @param i Right end of interval. Note that closed-interval [0,i].
* @return T Summation values in [0,i].
*/
T sum(int i) {
T res = 0;
for(++i; i > 0; i -= i & -i) {
res = res + dat[i];
}
return res;
}
/**
* @brief Sum values in [l,r]
*
* @param l Left end of interval.
* @param r Right end of interval.
* @return T Summation values in [l,r]
*/
T sum(int l, int r) { return sum(r) - sum(l - 1); }
/**
* @brief Sum all values.
*
* @return T Summation values.
*/
T sumAll() { return sum(n - 1); }
/**
* @brief If regard as histogram of elements, get k-th element.
*
* @param k Get k-th element.
* @return int Index to which k-th element belongs.
*/
int get(T k) {
++k;
int res = 0;
int N = 1;
while(N < n)
N *= 2;
for(int i = N / 2; i > 0; i /= 2) {
if(res + i < n && dat[res + i] < k) {
k = k - dat[res + i];
res = res + i;
}
}
return res + 1;
}
};
/**
* @brief 座標圧縮
*
* @tparam T データ型
* @param X 圧縮する数列 副作用により圧縮後の値が入る
* @return std::vector<T> ソートして重複を除去した元数列
*/
template <typename T> std::vector<T> compress(std::vector<T> &X) {
std::vector<T> vals = X;
std::sort(vals.begin(), vals.end());
vals.erase(unique(vals.begin(), vals.end()), vals.end());
for(int i = 0; i < X.size(); i++) {
X[i] = lower_bound(vals.begin(), vals.end(), X[i]) - vals.begin();
}
return vals;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
INT(q, k);
FenwickTree<ll> bit(200010);
vector<pll> query(q);
vector<ll> vals;
rep(i, q) {
INT(a);
if(a == 1) {
LL(v);
query[i] = {a, v};
vals.emplace_back(v);
} else {
query[i] = {a, 0};
}
}
auto dict = compress(vals);
int now = 0;
for(auto [a, v] : query) {
if(a == 1) {
bit.add(vals[now++], 1);
} else {
if(bit.sumAll() < k) {
cout << -1 << endl;
} else {
int val = bit.get(k - 1);
cout << dict[val - 1] << endl;
bit.add(val - 1, -1);
}
}
}
}
rokahikou1