結果
問題 | No.3025 Chocol∀te |
ユーザー |
👑 ![]() |
提出日時 | 2025-02-13 21:06:22 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,407 ms / 2,000 ms |
コード長 | 1,497 bytes |
コンパイル時間 | 1,797 ms |
コンパイル使用メモリ | 204,784 KB |
実行使用メモリ | 34,412 KB |
最終ジャッジ日時 | 2025-02-14 14:58:40 |
合計ジャッジ時間 | 26,812 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 73 |
ソースコード
#include<bits/stdc++.h>using namespace std;using ll = long long;#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)#define all(p) (p).begin(),(p).end()int main(){ios::sync_with_stdio(false);cin.tie(nullptr);int N, M;cin >> N >> M;vector<unordered_set<int>> G(N);vector<ll> A(N);vector<ll> sum(N);vector<int> big(N);vector<int> big_deg;const int B = 500;auto add_edge = [&](int from, int to) -> void {if (G[from].count(to)){G[from].erase(to);if (big[from] == 0){sum[to] -= A[from];}}else{G[from].insert(to);if (big[from] == 0){sum[to] += A[from];if (B == (int)G[from].size()){big_deg.push_back(from);big[from] = 1;for (auto x : G[from]) sum[x] -= A[from];}}}};auto upd_A = [&](int ind, ll a) -> void {ll diff = a - A[ind];A[ind] = a;if (big[ind] == 0){for (auto x : G[ind]) sum[x] += diff;}};for (int i = 0; i < M; i++){int a, b;cin >> a >> b;a--, b--;add_edge(a, b);add_edge(b, a);}for (int i = 0; i < N; i++){int a;cin >> a;upd_A(i, a);}ll ans = 0;int Q;cin >> Q;while (Q--){int t;cin >> t;if (t == 1){int a, b;cin >> a >> b;a--, b--;add_edge(a, b);add_edge(b, a);}if (t == 2){int i, a;cin >> i >> a;i--;upd_A(i, a);}if (t == 3){int c;cin >> c;c--;ans = sum[c];for (auto x : big_deg) if (G[x].count(c)) ans += A[x];cout << ans << "\n";}}}