結果
| 問題 |
No.2640 traO Stamps
|
| コンテスト | |
| ユーザー |
emthrm
|
| 提出日時 | 2024-02-19 21:48:05 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 62 ms / 2,000 ms |
| コード長 | 5,069 bytes |
| コンパイル時間 | 2,956 ms |
| コンパイル使用メモリ | 258,616 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-09-29 01:44:44 |
| 合計ジャッジ時間 | 7,164 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 33 |
ソースコード
#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;
}
emthrm