結果

問題 No.649 ここでちょっとQK!
ユーザー cielciel
提出日時 2018-02-10 01:01:47
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2,933 ms / 3,000 ms
コード長 410 bytes
コンパイル時間 892 ms
コンパイル使用メモリ 63,372 KB
最終ジャッジ日時 2025-01-05 08:18:16
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |         scanf("%d%d",&Q,&K);
      |         ~~~~~^~~~~~~~~~~~~~
main.cpp:12:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |                 scanf("%d",&q);
      |                 ~~~~~^~~~~~~~~
main.cpp:14:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |                         scanf("%lld",&n);
      |                         ~~~~~^~~~~~~~~~~

ソースコード

diff #

#include <deque>
#include <algorithm>
#include <cstdio>
using namespace std;

int main(){
	deque<long long>v;
	int Q,K,q;
	long long n;
	scanf("%d%d",&Q,&K);
	for(;Q--;){
		scanf("%d",&q);
		if(q==1){
			scanf("%lld",&n);
			auto it=lower_bound(v.begin(),v.end(),n);
			v.insert(it,n);
		}else{
			if(v.size()<K){
				puts("-1");
			}else{
				printf("%lld\n",v[K-1]);
				v.erase(v.begin()+K-1);
			}
		}
	}
}
0