結果
| 問題 |
No.649 ここでちょっとQK!
|
| コンテスト | |
| ユーザー |
ikd
|
| 提出日時 | 2018-02-12 17:32:28 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 206 ms / 3,000 ms |
| コード長 | 896 bytes |
| コンパイル時間 | 904 ms |
| コンパイル使用メモリ | 120,016 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-12 23:53:08 |
| 合計ジャッジ時間 | 5,294 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 |
ソースコード
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
import std.container;
int q, k; rd(q, k);
auto qmax=new BinaryHeap!(Array!(long))(),
qmin=new BinaryHeap!(Array!(long), "a>b")();
while(q--){
auto args=readln.split.to!(long[]);
if(args[0]==1){
auto v=args[1];
if(qmax.length<k) qmax.insert(v);
else if(qmax.front<=v) qmin.insert(v);
else{qmin.insert(qmax.front); qmax.popFront; qmax.insert(v);}
}else{
if(qmax.length>=k){
writeln(qmax.front);
qmax.popFront;
if(qmax.length<k && qmin.length>0){
qmax.insert(qmin.front);
qmin.popFront;
}
}else{
writeln(-1);
}
}
}
}
void rd(T...)(ref T x){
import std.stdio, std.string, std.conv;
auto l=readln.split;
assert(l.length==x.length);
foreach(i, ref e; x){
e=l[i].to!(typeof(e));
}
}
ikd