結果
問題 | No.230 Splarraay スプラレェーイ |
ユーザー | 👑 hos.lyric |
提出日時 | 2019-01-15 13:48:28 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 852 ms / 5,000 ms |
コード長 | 3,071 bytes |
コンパイル時間 | 983 ms |
コンパイル使用メモリ | 117,760 KB |
実行使用メモリ | 20,352 KB |
最終ジャッジ日時 | 2024-06-13 02:47:13 |
合計ジャッジ時間 | 6,810 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,944 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,944 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 5 ms
6,944 KB |
testcase_06 | AC | 34 ms
6,944 KB |
testcase_07 | AC | 4 ms
6,944 KB |
testcase_08 | AC | 8 ms
6,940 KB |
testcase_09 | AC | 372 ms
13,984 KB |
testcase_10 | AC | 237 ms
5,376 KB |
testcase_11 | AC | 203 ms
12,416 KB |
testcase_12 | AC | 375 ms
13,952 KB |
testcase_13 | AC | 51 ms
5,376 KB |
testcase_14 | AC | 283 ms
20,352 KB |
testcase_15 | AC | 558 ms
20,352 KB |
testcase_16 | AC | 692 ms
20,352 KB |
testcase_17 | AC | 852 ms
20,352 KB |
testcase_18 | AC | 463 ms
20,352 KB |
testcase_19 | AC | 504 ms
19,840 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); long[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) { } }