結果
問題 | No.2640 traO Stamps |
ユーザー | 👑 hos.lyric |
提出日時 | 2024-02-19 22:21:38 |
言語 | D (dmd 2.106.1) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,304 bytes |
コンパイル時間 | 1,864 ms |
コンパイル使用メモリ | 120,096 KB |
実行使用メモリ | 24,000 KB |
最終ジャッジ日時 | 2024-09-29 02:15:28 |
合計ジャッジ時間 | 9,048 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | AC | 1 ms
6,816 KB |
testcase_04 | RE | - |
testcase_05 | AC | 1 ms
6,820 KB |
testcase_06 | AC | 138 ms
14,416 KB |
testcase_07 | AC | 131 ms
6,908 KB |
testcase_08 | AC | 153 ms
17,520 KB |
testcase_09 | AC | 125 ms
7,200 KB |
testcase_10 | AC | 143 ms
17,440 KB |
testcase_11 | AC | 117 ms
6,816 KB |
testcase_12 | AC | 132 ms
20,656 KB |
testcase_13 | AC | 117 ms
6,820 KB |
testcase_14 | AC | 152 ms
17,604 KB |
testcase_15 | AC | 134 ms
14,660 KB |
testcase_16 | AC | 120 ms
17,144 KB |
testcase_17 | AC | 136 ms
17,152 KB |
testcase_18 | AC | 130 ms
6,816 KB |
testcase_19 | AC | 148 ms
22,640 KB |
testcase_20 | AC | 144 ms
22,848 KB |
testcase_21 | AC | 128 ms
13,772 KB |
testcase_22 | AC | 148 ms
18,496 KB |
testcase_23 | AC | 123 ms
6,816 KB |
testcase_24 | AC | 141 ms
14,084 KB |
testcase_25 | AC | 147 ms
21,928 KB |
testcase_26 | AC | 128 ms
13,852 KB |
testcase_27 | AC | 130 ms
13,920 KB |
testcase_28 | AC | 128 ms
13,876 KB |
testcase_29 | AC | 139 ms
13,868 KB |
testcase_30 | RE | - |
testcase_31 | AC | 170 ms
22,568 KB |
testcase_32 | AC | 151 ms
16,860 KB |
testcase_33 | AC | 158 ms
17,204 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; } string COLOR(string s = "") { return "\x1b[" ~ s ~ "m"; } 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; 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; } void main() { try { for (; ; ) { const N = readInt; const M = readInt; const K = readInt; auto S = new int[K + 1]; foreach (k; 0 .. K + 1) { S[k] = readInt - 1; } auto A = new int[M]; auto B = new int[M]; auto C = new long[M]; foreach (i; 0 .. M) { A[i] = readInt - 1; B[i] = readInt - 1; C[i] = readInt; } auto d = new long[][](N, N); foreach (u; 0 .. N) { d[u][] = INF; d[u][u] = 0; } foreach (i; 0 .. M) { chmin(d[A[i]][B[i]], C[i]); chmin(d[B[i]][A[i]], C[i]); } foreach (w; 0 .. N) foreach (u; 0 .. N) foreach (v; 0 .. N) { chmin(d[u][v], d[u][w] + d[w][v]); } auto us = S.dup; auto fs = new long[K]; foreach (k; 0 .. K) { fs[k] = d[us[k]][us[k + 1]]; } auto bit = fs.dup; foreach (k; 0 .. K) { const kk = k | k + 1; if (kk < K) bit[kk] += bit[k]; } const Q = readInt; foreach (q; 0 .. Q) { const T = readInt; if (T == 1) { const X = readInt; const U = readInt - 1; us[X] = U; foreach (k; [X - 1, X]) if (0 <= k && k <= X) { const ff = d[us[k]][us[k + 1]]; bit.bAdd(k, ff - fs[k]); fs[k] = ff; } } else if (T == 2) { const L = readInt; const R = readInt; const ans = bit.bSum(R) - bit.bSum(L); writeln(ans); } else { assert(false); } } } } catch (EOFException e) { } }