結果
問題 |
No.649 ここでちょっとQK!
|
ユーザー |
|
提出日時 | 2022-10-04 22:57:21 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 259 ms / 3,000 ms |
コード長 | 2,428 bytes |
コンパイル時間 | 3,696 ms |
コンパイル使用メモリ | 257,344 KB |
最終ジャッジ日時 | 2025-02-07 21:31:29 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 32 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> // clang-format off #define rep(i, s ,n) for(int i=s, i##_len=(n); i<i##_len; ++i) template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } using ll = long long; // 2^60 #define INF (1LL << 60) int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; using namespace std; using namespace atcoder; using Graph = vector<vector<int>>; template <typename T> ostream &operator<<(ostream &s, vector<vector<vector<T>>> const &v) { for (int i = 0; i < int(v.size()); ++i) { s << "[" << i << "]" << endl; s << v[i];} return s;} template <typename T> ostream &operator<<(ostream &s, vector<vector<T>> const &v) { for (int i = 0; i < int(v.size()); ++i ){ s << v[i];} return s;} template <typename T> ostream &operator<<(ostream &s, vector<T> const &v) { for (int i = 0; i < int(v.size()); ++i) { s << v[i]; if (i != int(v.size()) - 1) { s << ",";}} s << endl; return s;} // clang-format on // 幅優先の例 // 入力: グラフ G と,探索の始点 s // 出力: s から各頂点への最短路長を表す配列 vector<int> BFS(const Graph &G, int s) { int N = (int)G.size(); // 頂点数 // vector<bool> seen(N, false); vector<int> dist(N, -1); // 全頂点を「未訪問」に初期化 queue<int> que; dist[s] = 0; que.push(s); while (!que.empty()) { int v = que.front(); que.pop(); for (int x : G[v]) { if (dist[x] != -1) continue; dist[x] = dist[v] + 1; que.push(x); } } return dist; } int main() { cout << fixed << setprecision(16); int q, k; cin >> q >> k; priority_queue<ll> q1; priority_queue<ll, vector<ll>, std::greater<ll>> q2; rep(i, 0, q) { int which; cin >> which; if (which == 1) { ll v; cin >> v; q1.push(v); if (int(q1.size()) >= k) { ll exch = q1.top(); q1.pop(); q2.push(exch); } } else { if (q2.size() == 0) { cout << -1 << endl; } else { cout << q2.top() << endl; q2.pop(); } } } }