結果
問題 | No.649 ここでちょっとQK! |
ユーザー | nanae |
提出日時 | 2018-02-09 23:48:29 |
言語 | D (dmd 2.107.1) |
結果 |
AC
|
実行時間 | 311 ms / 3,000 ms |
コード長 | 2,317 bytes |
コンパイル時間 | 758 ms |
コンパイル使用メモリ | 97,800 KB |
実行使用メモリ | 26,756 KB |
最終ジャッジ日時 | 2023-09-03 18:40:28 |
合計ジャッジ時間 | 7,430 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | AC | 2 ms
4,376 KB |
testcase_03 | AC | 177 ms
7,424 KB |
testcase_04 | AC | 270 ms
24,920 KB |
testcase_05 | AC | 266 ms
24,708 KB |
testcase_06 | AC | 217 ms
9,068 KB |
testcase_07 | AC | 2 ms
4,376 KB |
testcase_08 | AC | 1 ms
4,376 KB |
testcase_09 | AC | 2 ms
4,380 KB |
testcase_10 | AC | 2 ms
4,376 KB |
testcase_11 | AC | 1 ms
4,376 KB |
testcase_12 | AC | 147 ms
11,116 KB |
testcase_13 | AC | 149 ms
11,644 KB |
testcase_14 | AC | 150 ms
11,056 KB |
testcase_15 | AC | 145 ms
10,544 KB |
testcase_16 | AC | 145 ms
10,540 KB |
testcase_17 | AC | 155 ms
11,088 KB |
testcase_18 | AC | 185 ms
21,144 KB |
testcase_19 | AC | 201 ms
22,120 KB |
testcase_20 | AC | 213 ms
25,988 KB |
testcase_21 | AC | 235 ms
23,968 KB |
testcase_22 | AC | 248 ms
24,452 KB |
testcase_23 | AC | 265 ms
23,452 KB |
testcase_24 | AC | 279 ms
25,752 KB |
testcase_25 | AC | 295 ms
24,980 KB |
testcase_26 | AC | 311 ms
26,756 KB |
testcase_27 | AC | 3 ms
4,376 KB |
testcase_28 | AC | 3 ms
4,376 KB |
testcase_29 | AC | 2 ms
4,376 KB |
testcase_30 | AC | 124 ms
9,804 KB |
testcase_31 | AC | 121 ms
9,792 KB |
testcase_32 | AC | 1 ms
4,376 KB |
testcase_33 | AC | 2 ms
4,376 KB |
testcase_34 | AC | 1 ms
4,376 KB |
testcase_35 | AC | 1 ms
4,376 KB |
ソースコード
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array; void main() { import std.typecons : Tuple; alias Query = Tuple!(int, "type", long, "value"); int q, k; scan(q, k); auto qs = new Query[](q); auto a = new long[](0); foreach (i ; 0 .. q) { auto line = readln.split.to!(long[]); if (line.length == 1) { qs[i] = Query(2, -1); } else { qs[i] = Query(1, line[1]); a ~= line[1]; } } a = a.sort().uniq.array; int[long] map; foreach (i, ai; a) { map[ai] = i.to!int; } auto ft = FenwickTree!(int)(q); foreach (i ; 0 .. q) { if (qs[i].type == 2) { if (ft.sum(q) < k) { writeln(-1); } else { int btm = 0, top = q; while (top - btm > 1) { int mid = (top + btm) / 2; if (ft.sum(mid) >= k) { top = mid; } else { btm = mid; } } writeln(a[top-1]); ft.add(top-1, -1); } } else { ft.add(map[qs[i].value], 1); } } } struct FenwickTree(T) { private { int size; T[] data; } this (int N) { size = N + 1; data = new T[](size); } void add(int i, int x) { i++; while (i < size) { data[i] += x; i += i & (-i); } } T sum(int r) { T res = 0; while (r > 0) { res += data[r]; r -= r & (-r); } return res; } } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }