結果
| 問題 | No.649 ここでちょっとQK! |
| コンテスト | |
| ユーザー |
packer_jp
|
| 提出日時 | 2018-02-09 23:10:02 |
| 言語 | C++11 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,191 bytes |
| 記録 | |
| コンパイル時間 | 1,194 ms |
| コンパイル使用メモリ | 181,256 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-04-25 03:12:07 |
| 合計ジャッジ時間 | 5,013 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge3_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 6 WA * 26 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:42:24: warning: ignoring return value of 'std::priority_queue<_Tp, _Sequence, _Compare>::const_reference std::priority_queue<_Tp, _Sequence, _Compare>::top() const [with _Tp = long long int; _Sequence = std::vector<long long int, std::allocator<long long int> >; _Compare = std::greater<long long int>; const_reference = const long long int&]', declared with attribute 'nodiscard' [-Wunused-result]
42 | pq2.top();
| ~~~~~~~^~
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/queue:72,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/x86_64-pc-linux-gnu/bits/stdc++.h:160,
from main.cpp:2:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_queue.h:823:7: note: declared here
823 | top() const
| ^~~
ソースコード
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
int Q, K;
priority_queue<int> pq1;
priority_queue<int, vector<int>, greater<int> > pq2;
vector<int> ans;
signed main() {
cin >> Q >> K;
for (int i = 0; i < Q; i++) {
int kind;
cin >> kind;
if (kind == 1) {
int v;
cin >> v;
if (pq1.size() < K) {
pq1.push(v);
} else if (v < pq1.top()) {
pq2.push(pq1.top());
pq1.pop();
pq1.push(v);
} else {
pq2.push(v);
}
} else {
if (pq1.size() < K) {
ans.push_back(-1);
} else if (pq2.empty()) {
ans.push_back(pq1.top());
pq1.pop();
} else {
ans.push_back(pq1.top());
pq1.pop();
pq1.push(pq2.top());
pq2.top();
}
}
}
for (int i = 0; i < ans.size(); i++) {
cout << ans[i] << endl;
}
return 0;
}
packer_jp