結果
問題 | No.631 Noelちゃんと電車旅行 |
ユーザー | 👑 hos.lyric |
提出日時 | 2019-01-31 14:16:55 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 239 ms / 2,000 ms |
コード長 | 2,998 bytes |
コンパイル時間 | 1,056 ms |
コンパイル使用メモリ | 120,452 KB |
実行使用メモリ | 12,960 KB |
最終ジャッジ日時 | 2024-06-13 04:09:11 |
合計ジャッジ時間 | 6,970 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 172 ms
9,500 KB |
testcase_01 | AC | 238 ms
12,960 KB |
testcase_02 | AC | 239 ms
11,992 KB |
testcase_03 | AC | 236 ms
11,840 KB |
testcase_04 | AC | 234 ms
11,396 KB |
testcase_05 | AC | 237 ms
11,536 KB |
testcase_06 | AC | 95 ms
7,472 KB |
testcase_07 | AC | 49 ms
6,944 KB |
testcase_08 | AC | 177 ms
12,788 KB |
testcase_09 | AC | 210 ms
11,788 KB |
testcase_10 | AC | 147 ms
11,596 KB |
testcase_11 | AC | 128 ms
7,544 KB |
testcase_12 | AC | 161 ms
12,724 KB |
testcase_13 | AC | 156 ms
6,944 KB |
testcase_14 | AC | 69 ms
6,940 KB |
testcase_15 | AC | 130 ms
6,944 KB |
testcase_16 | AC | 1 ms
6,940 KB |
testcase_17 | AC | 2 ms
6,944 KB |
testcase_18 | AC | 1 ms
6,940 KB |
testcase_19 | AC | 1 ms
6,944 KB |
testcase_20 | AC | 2 ms
6,944 KB |
ソースコード
import std.conv, std.functional, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.container, std.math, std.numeric, 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; } 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)); } enum INF = 10L^^18; class SegmentTree { int n; long[] mx, add; this(long[] ini) { const n_ = cast(int)(ini.length); for (n = 1; n < n_; n <<= 1) {} mx = new long[n << 1]; add = new long[n << 1]; mx[] = -INF; add[] = 0; foreach (i; 0 .. n_) { mx[n + i] = ini[i]; } foreach_reverse (a; 1 .. n) { mx[a] = max(mx[a << 1], mx[a << 1 | 1]); } } // [a, b) private long query(int u, int x, int y, int a, int b, long val) { chmax(a, x); chmin(b, y); if (a >= b) { return -INF; } if (a == x && b == y) { mx[u] += val; add[u] += val; return mx[u]; } assert(u < n); const uL = u << 1 | 0; const uR = u << 1 | 1; const mid = (x + y) >> 1; if (add[u] != 0) { mx[uL] += add[u]; mx[uR] += add[u]; add[uL] += add[u]; add[uR] += add[u]; add[u] = 0; } const resL = query(uL, x, mid, a, b, val); const resR = query(uR, mid, y, a, b, val); mx[u] = max(mx[uL], mx[uR]); return max(resL, resR); } // [a, b] long query(int a, int b, long val) { return query(1, 0, n, a, b + 1, val); } } int N; long[] T; int M; int[] L, R; long[] D; void main() { try { for (; ; ) { N = readInt(); T = new long[N - 1]; foreach (i; 0 .. N - 1) { T[i] = readLong(); } M = readInt(); L = new int[M]; R = new int[M]; D = new long[M]; foreach (m; 0 .. M) { L[m] = readInt() - 1; R[m] = readInt() - 1; D[m] = readInt(); } auto ini = new long[N]; foreach (i; 0 .. N - 1) { ini[i] = T[i] + 3 * (N - 1 - i); } auto seg = new SegmentTree(ini); foreach (m; 0 .. M) { seg.query(L[m], R[m], D[m]); writeln(seg.mx[1]); } } } catch (EOFException e) { } }