結果
問題 | No.1347 HS Railway |
ユーザー | 👑 hos.lyric |
提出日時 | 2021-01-16 16:51:24 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 430 ms / 2,000 ms |
コード長 | 3,524 bytes |
コンパイル時間 | 1,189 ms |
コンパイル使用メモリ | 142,544 KB |
実行使用メモリ | 47,872 KB |
最終ジャッジ日時 | 2024-06-22 10:36:47 |
合計ジャッジ時間 | 13,657 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 3 ms
5,376 KB |
testcase_03 | AC | 4 ms
5,376 KB |
testcase_04 | AC | 4 ms
5,376 KB |
testcase_05 | AC | 3 ms
5,376 KB |
testcase_06 | AC | 3 ms
5,376 KB |
testcase_07 | AC | 4 ms
5,376 KB |
testcase_08 | AC | 5 ms
5,376 KB |
testcase_09 | AC | 3 ms
5,376 KB |
testcase_10 | AC | 4 ms
5,376 KB |
testcase_11 | AC | 3 ms
5,376 KB |
testcase_12 | AC | 111 ms
14,336 KB |
testcase_13 | AC | 108 ms
12,032 KB |
testcase_14 | AC | 45 ms
7,552 KB |
testcase_15 | AC | 27 ms
12,528 KB |
testcase_16 | AC | 131 ms
16,288 KB |
testcase_17 | AC | 38 ms
7,296 KB |
testcase_18 | AC | 257 ms
33,776 KB |
testcase_19 | AC | 288 ms
32,512 KB |
testcase_20 | AC | 137 ms
20,696 KB |
testcase_21 | AC | 24 ms
10,624 KB |
testcase_22 | AC | 233 ms
24,324 KB |
testcase_23 | AC | 250 ms
29,824 KB |
testcase_24 | AC | 80 ms
12,288 KB |
testcase_25 | AC | 169 ms
29,056 KB |
testcase_26 | AC | 238 ms
32,108 KB |
testcase_27 | AC | 143 ms
20,864 KB |
testcase_28 | AC | 160 ms
24,412 KB |
testcase_29 | AC | 242 ms
33,120 KB |
testcase_30 | AC | 183 ms
27,136 KB |
testcase_31 | AC | 171 ms
24,404 KB |
testcase_32 | AC | 318 ms
34,980 KB |
testcase_33 | AC | 305 ms
45,040 KB |
testcase_34 | AC | 346 ms
35,256 KB |
testcase_35 | AC | 287 ms
43,896 KB |
testcase_36 | AC | 323 ms
45,396 KB |
testcase_37 | AC | 338 ms
45,856 KB |
testcase_38 | AC | 370 ms
47,352 KB |
testcase_39 | AC | 399 ms
45,748 KB |
testcase_40 | AC | 275 ms
44,556 KB |
testcase_41 | AC | 300 ms
45,440 KB |
testcase_42 | AC | 415 ms
47,872 KB |
testcase_43 | AC | 263 ms
39,936 KB |
testcase_44 | AC | 329 ms
45,568 KB |
testcase_45 | AC | 283 ms
44,416 KB |
testcase_46 | AC | 307 ms
35,584 KB |
testcase_47 | AC | 405 ms
47,104 KB |
testcase_48 | AC | 430 ms
45,820 KB |
testcase_49 | AC | 352 ms
45,952 KB |
testcase_50 | AC | 406 ms
47,100 KB |
testcase_51 | AC | 339 ms
34,048 KB |
ソースコード
import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } void bAdd(T)(T[] bit, int pos, T val) in { assert(0 <= pos && pos < bit.length, "bAdd: 0 <= pos < |bit| must hold"); } do { for (int x = pos; x < bit.length; x |= x + 1) { bit[x] += val; } } // sum of [0, pos) T bSum(T)(T[] bit, int pos) in { assert(0 <= pos && pos <= bit.length, "bSum: 0 <= pos <= |bit| must hold"); } do { T ret = 0; for (int x = pos - 1; x >= 0; x = (x & (x + 1)) - 1) { ret += bit[x]; } return ret; } enum K = 5; void main() { try { for (; ; ) { const N = readInt(); auto L = new int[K]; auto R = new int[K]; auto A = new long[][](K, N - 1); foreach (k; 0 .. K) { L[k] = readInt() - 1; R[k] = readInt() - 1; foreach (i; L[k] .. R[k]) { A[k][i] = readLong(); } } const M = readInt(); auto B = new int[M]; auto S = new long[M]; foreach (m; 0 .. M) { B[m] = readInt() - 1; S[m] = readLong(); } auto ASum = new long[][](K, N); foreach (k; 0 .. K) { foreach (i; 0 .. N - 1) { ASum[k][i + 1] = ASum[k][i] + A[k][i]; } } const xs = (L ~ R).sort.uniq.array; const xsLen = cast(int)(xs.length); long ans; foreach (j; 0 .. xsLen) { const x = xs[j]; int[long] cnt; foreach (m; 0 .. M) { const k = B[m]; if (L[k] <= x && x <= R[k]) { const s = S[m] + ASum[k][x]; if (s in cnt) { ans += cnt[s]; } ++cnt[s]; } } } foreach (j; 0 .. xsLen - 1) { const l = xs[j], r = xs[j + 1]; alias Entry = Tuple!(long, "s", long, "t"); Entry[] es; foreach (m; 0 .. M) { const k = B[m]; if (L[k] <= l && r <= R[k]) { es ~= Entry(S[m] + ASum[k][l], S[m] + ASum[k][r]); } } es.sort; long[] ts; foreach (ref e; es) { ts ~= e.t; } ts = ts.sort.uniq.array; auto bit = new int[ts.length]; int tot; foreach (ref e; es) { const pos = ts.lowerBound(e.t); ans += tot - bit.bSum(pos + 1); bit.bAdd(pos, 1); ++tot; } } writeln(ans); } } catch (EOFException e) { } }