結果

問題 No.2640 traO Stamps
ユーザー tnakao0123tnakao0123
提出日時 2024-02-20 18:07:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 2,335 bytes
コンパイル時間 728 ms
コンパイル使用メモリ 56,052 KB
実行使用メモリ 8,096 KB
最終ジャッジ日時 2024-02-20 18:07:54
合計ジャッジ時間 6,244 ms
ジャッジサーバーID
(参考情報)
judge14 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 86 ms
7,868 KB
testcase_07 AC 90 ms
7,788 KB
testcase_08 AC 98 ms
7,984 KB
testcase_09 AC 82 ms
6,676 KB
testcase_10 AC 92 ms
7,992 KB
testcase_11 AC 80 ms
6,676 KB
testcase_12 AC 91 ms
7,976 KB
testcase_13 AC 77 ms
6,676 KB
testcase_14 AC 98 ms
8,008 KB
testcase_15 AC 86 ms
6,676 KB
testcase_16 AC 82 ms
7,928 KB
testcase_17 AC 88 ms
7,964 KB
testcase_18 AC 88 ms
6,676 KB
testcase_19 AC 94 ms
8,020 KB
testcase_20 AC 98 ms
8,012 KB
testcase_21 AC 82 ms
6,676 KB
testcase_22 AC 97 ms
8,028 KB
testcase_23 AC 83 ms
6,676 KB
testcase_24 AC 88 ms
6,676 KB
testcase_25 AC 94 ms
8,068 KB
testcase_26 AC 79 ms
8,096 KB
testcase_27 AC 80 ms
8,096 KB
testcase_28 AC 78 ms
8,096 KB
testcase_29 AC 87 ms
8,096 KB
testcase_30 AC 114 ms
8,052 KB
testcase_31 AC 104 ms
8,064 KB
testcase_32 AC 101 ms
7,932 KB
testcase_33 AC 107 ms
7,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2640.cc:  No.2640 traO Stamps - yukicoder
 */

#include<cstdio>
#include<vector>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 200;
const int MAX_K = 200000;
const long long LINF = 1LL << 60;

/* typedef */

typedef long long ll;
typedef vector<int> vi;

template <typename T>
struct SegTreeSum {
  int e2;
  vector<T> nodes;
  T defv;
  SegTreeSum() {}

  void init(int n, T _defv) {
    defv = _defv;
    for (e2 = 1; e2 < n; e2 <<= 1);
    nodes.assign(e2 * 2, defv);
  }

  T &geti(int i) { return nodes[e2 - 1 + i]; }
  void seti(int i, T v) { geti(i) = v; }

  void setall() {
    for (int j = e2 - 2; j >= 0; j--)
      nodes[j] = nodes[j * 2 + 1] + nodes[j * 2 + 2];
  }

  void set(int i, T v) {
    int j = e2 - 1 + i;
    nodes[j] = v;
    while (j > 0) {
      j = (j - 1) / 2;
      nodes[j] = nodes[j * 2 + 1] + nodes[j * 2 + 2];
    }
  }

  T sum_range(int r0, int r1, int k, int i0, int i1) {
    if (r1 <= i0 || i1 <= r0) return defv;
    if (r0 <= i0 && i1 <= r1) return nodes[k];

    int im = (i0 + i1) / 2;
    T v0 = sum_range(r0, r1, k * 2 + 1, i0, im);
    T v1 = sum_range(r0, r1, k * 2 + 2, im, i1);
    return v0 + v1;
  }
  T sum_range(int r0, int r1) { return sum_range(r0, r1, 0, 0, e2); }
};

/* global variables */

int ss[MAX_K + 1];
ll ds[MAX_N][MAX_N];
SegTreeSum<ll> st;

/* subroutines */

/* main */

int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i <= k; i++) scanf("%d", ss + i), ss[i]--;

  for (int i = 0; i < n; i++)
    fill(ds[i], ds[i] + n, LINF), ds[i][i] = 0;
  ;
  for (int i = 0; i < m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    u--, v--;
    ds[u][v] = ds[v][u] = w;
  }

  for (int l = 0; l < n; l++)
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
	ds[i][j] = min(ds[i][j], ds[i][l] + ds[l][j]);

  st.init(k, 0);
  for (int i = 0; i < k; i++) st.seti(i, ds[ss[i]][ss[i + 1]]);
  st.setall();
  
  int qn;
  scanf("%d", &qn);

  while (qn--) {
    int op, x, y;
    scanf("%d%d%d", &op, &x, &y);

    if (op == 1) {
      y--;
      ss[x] = y;
      if (x > 0) st.set(x - 1, ds[ss[x - 1]][ss[x]]);
      if (x < k) st.set(x, ds[ss[x]][ss[x + 1]]);
    }
    else {
      auto e = st.sum_range(x, y);
      printf("%lld\n", e);
    }
  }
  return 0;
}
0