結果
問題 | No.59 鉄道の旅 |
ユーザー | te-sh |
提出日時 | 2018-01-10 14:57:19 |
言語 | D (dmd 2.107.1) |
結果 |
AC
|
実行時間 | 32 ms / 5,000 ms |
コード長 | 1,224 bytes |
コンパイル時間 | 586 ms |
コンパイル使用メモリ | 84,776 KB |
実行使用メモリ | 8,524 KB |
最終ジャッジ日時 | 2023-09-03 18:02:53 |
合計ジャッジ時間 | 1,845 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
7,932 KB |
testcase_01 | AC | 3 ms
7,940 KB |
testcase_02 | AC | 3 ms
6,696 KB |
testcase_03 | AC | 2 ms
7,084 KB |
testcase_04 | AC | 32 ms
8,448 KB |
testcase_05 | AC | 3 ms
6,412 KB |
testcase_06 | AC | 3 ms
7,140 KB |
testcase_07 | AC | 2 ms
6,480 KB |
testcase_08 | AC | 5 ms
7,148 KB |
testcase_09 | AC | 5 ms
6,928 KB |
testcase_10 | AC | 6 ms
7,420 KB |
testcase_11 | AC | 5 ms
7,120 KB |
testcase_12 | AC | 22 ms
8,200 KB |
testcase_13 | AC | 28 ms
7,804 KB |
testcase_14 | AC | 28 ms
8,524 KB |
testcase_15 | AC | 3 ms
7,164 KB |
ソースコード
import std.algorithm, std.conv, std.range, std.stdio, std.string; T read1(T)(){return readln.chomp.to!T;} void read2(S,T)(ref S a,ref T b){auto r=readln.splitter;a=r.front.to!S;r.popFront;b=r.front.to!T;} const auto maxW = 1_000_000; void main() { int n, k; read2(n, k); auto bt = BiTree!int(maxW+1); foreach (_; 0..n) { auto w = read1!int; if (w > 0) { if (bt[w..$] < k) ++bt[w]; } else { w = -w; if (bt[w] > 0) --bt[w]; } } writeln(bt[0..$]); } struct BiTree(T) { const size_t n; T[] buf; this(size_t n) { this.n = n; this.buf = new T[](n+1); } void opIndexOpAssign(string op)(T val, size_t i) if (op == "+" || op == "-") { ++i; for (; i <= n; i += i & -i) mixin("buf[i] " ~ op ~ "= val;"); } void opIndexUnary(string op)(size_t i) if (op == "++" || op == "--") { ++i; for (; i <= n; i += i & -i) mixin("buf[i]" ~ op ~ ";"); } pure T opSlice(size_t r, size_t l) { return get(l) - get(r); } pure T opIndex(size_t i) { return opSlice(i, i+1); } pure size_t opDollar() { return n; } private: pure T get(size_t i) { auto s = T(0); for (; i > 0; i -= i & -i) s += buf[i]; return s; } }