結果
問題 | No.230 Splarraay スプラレェーイ |
ユーザー | 👑 hos.lyric |
提出日時 | 2019-01-15 13:47:52 |
言語 | D (dmd 2.106.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,070 bytes |
コンパイル時間 | 1,188 ms |
コンパイル使用メモリ | 118,892 KB |
実行使用メモリ | 23,020 KB |
最終ジャッジ日時 | 2024-06-13 02:47:05 |
合計ジャッジ時間 | 7,310 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 1 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 5 ms
6,940 KB |
testcase_06 | AC | 34 ms
6,940 KB |
testcase_07 | AC | 4 ms
6,940 KB |
testcase_08 | AC | 9 ms
6,948 KB |
testcase_09 | AC | 372 ms
13,920 KB |
testcase_10 | AC | 232 ms
6,940 KB |
testcase_11 | AC | 198 ms
13,788 KB |
testcase_12 | AC | 370 ms
13,976 KB |
testcase_13 | AC | 51 ms
6,944 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 677 ms
21,528 KB |
testcase_17 | AC | 849 ms
20,476 KB |
testcase_18 | AC | 452 ms
22,264 KB |
testcase_19 | AC | 506 ms
21,344 KB |
ソースコード
import std.conv, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.container, std.math, std.range, 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; } void chmin(T)(ref T t, in T f) { if (t > f) t = f; } void chmax(T)(ref T t, in T f) { if (t < f) t = f; } int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; } int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a < val)); } int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a <= val)); } class SegmentTree { enum NUM_COLORS = 2; int n; int[][] cnt; int[] add; this(int n_) { for (n = 1; n < n_; n <<= 1) {} cnt = new int[][](n << 1, NUM_COLORS); add = new int[n << 1]; add[] = -1; } private int[] query(int u, int l, int r, int a, int b, int val) { chmax(a, l); chmin(b, r); if (a >= b) { return new int[NUM_COLORS]; } if (a == l && b == r) { if (val != -1) { cnt[u][] = 0; cnt[u][val] = r - l; add[u] = val; } return cnt[u]; } const uL = u << 1; const uR = u << 1 | 1; const mid = (l + r) >> 1; if (add[u] != -1) { cnt[uL][] = 0; cnt[uL][add[u]] = mid - l; cnt[uR][] = 0; cnt[uR][add[u]] = r - mid; add[uL] = add[u]; add[uR] = add[u]; add[u] = -1; } const resL = query(uL, l, mid, a, b, val); const resR = query(uR, mid, r, a, b, val); auto ret = new int[NUM_COLORS]; foreach (color; 0 .. NUM_COLORS) { cnt[u][color] = cnt[uL][color] + cnt[uR][color]; ret[color] = resL[color] + resR[color]; } return ret; } int[] query(int a, int b, int val) { return query(1, 0, n, a, b + 1, val); } } int N, Q; int[] X, L, R; void main() { try { for (; ; ) { N = readInt(); Q = readInt(); X = new int[Q]; L = new int[Q]; R = new int[Q]; foreach (q; 0 .. Q) { X[q] = readInt() - 1; L[q] = readInt(); R[q] = readInt(); } auto seg = new SegmentTree(N); int[2] ans; foreach (q; 0 .. Q) { const res = seg.query(L[q], R[q], X[q]); if (X[q] == -1) { if (res[0] > res[1]) { ans[0] += res[0]; } else if (res[0] < res[1]) { ans[1] += res[1]; } } } { const res = seg.query(0, N - 1, -1); ans[0] += res[0]; ans[1] += res[1]; } writeln(ans[0], " ", ans[1]); } } catch (EOFException e) { } }