結果
| 問題 | No.649 ここでちょっとQK! |
| コンテスト | |
| ユーザー |
yukinon0808
|
| 提出日時 | 2018-02-10 00:05:23 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,272 bytes |
| 記録 | |
| コンパイル時間 | 738 ms |
| コンパイル使用メモリ | 82,164 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-09 06:52:38 |
| 合計ジャッジ時間 | 7,664 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 RE * 3 |
| other | WA * 1 RE * 31 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:54:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
54 | scanf("%d", &a);
| ~~~~~^~~~~~~~~~
main.cpp:56:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
56 | scanf("%lld", &b);
| ~~~~~^~~~~~~~~~~~
ソースコード
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#define INF 1e9
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
vector<ll> S;
ll my_remove(int i) {
ll res = S[i];
S.erase(S.begin() + i);
return res;
}
int my_binary_search(int l, int r, ll b) {
if (r - l == 1) {
return r;
}
int c = (l + r) / 2;
if (S[c] == b) {
return c;
} else if (S[c] > b) {
return my_binary_search(l, c, b);
} else {
return my_binary_search(c, r, b);
}
}
void my_insert(ll b) {
int i = my_binary_search(0, int(S.size()), b);
S.insert(S.begin() + i, b);
}
int main() {
int Q, K;
cin >> Q >> K;
for (int i = 0; i < Q; ++i) {
int a; ll b;
scanf("%d", &a);
if (a == 1) {
scanf("%lld", &b);
my_insert(b);
} else {
if (S.size() >= K) {
ll res = my_remove(K);
printf("%lld", res);
} else {
printf("%d", -1);
}
}
}
return 0;
}
yukinon0808