結果
問題 | No.2640 traO Stamps |
ユーザー | 👑 emthrm |
提出日時 | 2024-02-19 21:45:16 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,068 bytes |
コンパイル時間 | 3,023 ms |
コンパイル使用メモリ | 257,916 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-09-29 01:39:59 |
合計ジャッジ時間 | 7,309 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,820 KB |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | WA | - |
testcase_05 | AC | 2 ms
6,816 KB |
testcase_06 | AC | 58 ms
6,816 KB |
testcase_07 | AC | 56 ms
6,816 KB |
testcase_08 | AC | 64 ms
6,816 KB |
testcase_09 | AC | 52 ms
6,816 KB |
testcase_10 | AC | 63 ms
6,816 KB |
testcase_11 | WA | - |
testcase_12 | AC | 58 ms
6,816 KB |
testcase_13 | AC | 50 ms
6,820 KB |
testcase_14 | AC | 64 ms
6,816 KB |
testcase_15 | AC | 56 ms
6,816 KB |
testcase_16 | AC | 54 ms
6,816 KB |
testcase_17 | AC | 59 ms
6,820 KB |
testcase_18 | AC | 56 ms
6,816 KB |
testcase_19 | AC | 63 ms
6,820 KB |
testcase_20 | AC | 62 ms
6,816 KB |
testcase_21 | AC | 54 ms
6,816 KB |
testcase_22 | AC | 64 ms
6,820 KB |
testcase_23 | AC | 53 ms
6,816 KB |
testcase_24 | AC | 58 ms
6,816 KB |
testcase_25 | AC | 63 ms
6,816 KB |
testcase_26 | AC | 54 ms
6,816 KB |
testcase_27 | AC | 54 ms
6,820 KB |
testcase_28 | AC | 52 ms
6,820 KB |
testcase_29 | AC | 57 ms
6,816 KB |
testcase_30 | AC | 69 ms
6,820 KB |
testcase_31 | AC | 72 ms
6,820 KB |
testcase_32 | AC | 64 ms
6,820 KB |
testcase_33 | AC | 65 ms
6,820 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) using ll = long long; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr double EPS = 1e-8; constexpr int MOD = 998244353; // constexpr int MOD = 1000000007; constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1}; constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1}; constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1}; template <typename T, typename U> inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; } template <typename T, typename U> inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << fixed << setprecision(20); } } iosetup; template <typename T> struct WarshallFloyd { std::vector<std::vector<T>> graph, dist; WarshallFloyd(const std::vector<std::vector<T>>& graph, const T inf) : graph(graph), dist(graph), inf(inf), n(graph.size()), internal(n, std::vector<int>(n, -1)) { for (int k = 0; k < n; ++k) { for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (dist[i][k] + dist[k][j] < dist[i][j]) { dist[i][j] = dist[i][k] + dist[k][j]; internal[i][j] = k; } } } } } void add(const int src, const int dst, const T cost) { srcs.emplace_back(src); dsts.emplace_back(dst); costs.emplace_back(cost); } void calc() { const int m = srcs.size(); for (int i = 0; i < m; ++i) { graph[srcs[i]][dsts[i]] = std::min(graph[srcs[i]][dsts[i]], costs[i]); if (costs[i] <= dist[srcs[i]][dsts[i]]) { dist[srcs[i]][dsts[i]] = costs[i]; internal[srcs[i]][dsts[i]] = -1; } } std::vector<int> vers(m * 2); std::copy(srcs.begin(), srcs.end(), vers.begin()); std::copy(dsts.begin(), dsts.end(), std::next(vers.begin(), m)); std::sort(vers.begin(), vers.end()); vers.erase(std::unique(vers.begin(), vers.end()), vers.end()); for (const int ver : vers) { for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (dist[i][j] > dist[i][ver] + dist[ver][j]) { dist[i][j] = dist[i][ver] + dist[ver][j]; internal[i][j] = ver; } } } } srcs.clear(); dsts.clear(); costs.clear(); } bool has_negative_cycle() const { for (int i = 0; i < n; ++i) { if (dist[i][i] < 0) return true; } return false; } std::vector<int> build_path(const int s, const int t) const { std::vector<int> res; if (dist[s][t] != inf) { build_path(s, t, &res); res.emplace_back(t); } return res; } private: const T inf; const int n; std::vector<int> srcs, dsts; std::vector<T> costs; std::vector<std::vector<int>> internal; void build_path(const int s, const int t, std::vector<int>* path) const { const int k = internal[s][t]; if (k == -1) { (*path).emplace_back(s); } else { build_path(s, k, path); build_path(k, t, path); } } }; template <typename Abelian> struct FenwickTree { explicit FenwickTree(const int n, const Abelian ID = 0) : n(n), ID(ID), data(n, ID) {} void add(int idx, const Abelian val) { for (; idx < n; idx |= idx + 1) { data[idx] += val; } } Abelian sum(int idx) const { Abelian res = ID; for (--idx; idx >= 0; idx = (idx & (idx + 1)) - 1) { res += data[idx]; } return res; } Abelian sum(const int left, const int right) const { return left < right ? sum(right) - sum(left) : ID; } Abelian operator[](const int idx) const { return sum(idx, idx + 1); } int lower_bound(Abelian val) const { if (val <= ID) [[unlikely]] return 0; int res = 0; for (int mask = std::bit_ceil(static_cast<unsigned int>(n + 1)) >> 1; mask > 0; mask >>= 1) { const int idx = res + mask - 1; if (idx < n && data[idx] < val) { val -= data[idx]; res += mask; } } return res; } private: const int n; const Abelian ID; std::vector<Abelian> data; }; int main() { int n, m, k; cin >> n >> m >> k; vector<int> s(k + 1); for (int& s_i : s) cin >> s_i, --s_i; vector graph(n, vector(n, LINF)); REP(i, n) graph[i][i] = 0; while (m--) { int a, b, c; cin >> a >> b >> c; --a; --b; graph[a][b] = graph[b][a] = c; } const WarshallFloyd wf(graph, LINF); FenwickTree<ll> bit(k + 1); FOR(i, 1, k + 1) bit.add(i, wf.dist[s[i - 1]][s[i]]); int q; cin >> q; while (q--) { int t, x, y; cin >> t >> x >> y; if (t == 1) { --y; s[x] = y; if (x > 0) { bit.add(x, -bit[x]); bit.add(x, wf.dist[s[x - 1]][s[x]]); } if (x + 1 < k) { bit.add(x + 1, -bit[x + 1]); bit.add(x + 1, wf.dist[s[x]][s[x + 1]]); } } else if (t == 2) { cout << bit.sum(x + 1, y + 1) << '\n'; } } return 0; }