結果

問題 No.649 ここでちょっとQK!
ユーザー htensaihtensai
提出日時 2020-06-12 12:53:43
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,215 bytes
コンパイル時間 2,956 ms
コンパイル使用メモリ 74,720 KB
実行使用メモリ 62,256 KB
最終ジャッジ日時 2023-09-06 09:05:25
合計ジャッジ時間 8,792 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
53,656 KB
testcase_01 AC 41 ms
49,220 KB
testcase_02 AC 41 ms
49,316 KB
testcase_03 AC 236 ms
56,004 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
	public static void main (String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] first = br.readLine().split(" ", 2);
		int q = Integer.parseInt(first[0]);
		int k = Integer.parseInt(first[1]);
		LinkedList<Long> list = new LinkedList<>();
		list.add(Long.MIN_VALUE);
		list.add(Long.MAX_VALUE);
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
		    String[] line = br.readLine().split(" ");
		    int type = Integer.parseInt(line[0]);
		    if (type == 1) {
		        long x = Long.parseLong(line[1]);
		        int left = 0;
		        int right = list.size();
		        while (right - left > 1) {
		            int m = (left + right) / 2;
		            if (list.get(m) > x) {
		                right = m;
		            } else {
		                left = m;
		            }
		        }
		        list.add(right, x);
		    } else {
		        if (list.size() - 2 < k) {
		            sb.append(-1);
		        } else {
		            sb.append(list.get(k));
    		        list.remove(k);
		        }
		        sb.append("\n");
		    }
		}
		System.out.print(sb);
	}
}
0