結果

問題 No.2640 traO Stamps
ユーザー 👑 hos.lyrichos.lyric
提出日時 2024-02-19 22:22:03
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 150 ms / 2,000 ms
コード長 3,303 bytes
コンパイル時間 710 ms
コンパイル使用メモリ 109,440 KB
実行使用メモリ 23,576 KB
最終ジャッジ日時 2024-02-19 22:22:12
合計ジャッジ時間 7,282 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 3 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 125 ms
14,480 KB
testcase_07 AC 121 ms
6,872 KB
testcase_08 AC 136 ms
17,548 KB
testcase_09 AC 108 ms
6,676 KB
testcase_10 AC 129 ms
17,476 KB
testcase_11 AC 110 ms
6,676 KB
testcase_12 AC 121 ms
20,824 KB
testcase_13 AC 105 ms
6,676 KB
testcase_14 AC 141 ms
17,492 KB
testcase_15 AC 117 ms
14,276 KB
testcase_16 AC 113 ms
17,212 KB
testcase_17 AC 120 ms
17,192 KB
testcase_18 AC 115 ms
6,676 KB
testcase_19 AC 141 ms
23,576 KB
testcase_20 AC 132 ms
23,516 KB
testcase_21 AC 110 ms
13,792 KB
testcase_22 AC 135 ms
18,772 KB
testcase_23 AC 112 ms
6,676 KB
testcase_24 AC 125 ms
13,668 KB
testcase_25 AC 131 ms
22,876 KB
testcase_26 AC 114 ms
13,872 KB
testcase_27 AC 118 ms
13,872 KB
testcase_28 AC 110 ms
13,872 KB
testcase_29 AC 125 ms
13,872 KB
testcase_30 AC 147 ms
23,516 KB
testcase_31 AC 150 ms
23,516 KB
testcase_32 AC 140 ms
16,820 KB
testcase_33 AC 141 ms
17,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 < K) {
            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) {
  }
}
0