結果
問題 | No.3025 Chocol∀te |
ユーザー |
👑 ![]() |
提出日時 | 2025-02-11 05:21:53 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 837 ms / 2,000 ms |
コード長 | 1,631 bytes |
コンパイル時間 | 2,423 ms |
コンパイル使用メモリ | 209,316 KB |
実行使用メモリ | 183,752 KB |
最終ジャッジ日時 | 2025-02-14 22:53:51 |
合計ジャッジ時間 | 28,205 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 77 |
ソースコード
#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;vector<vector<int>> H(N);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{H[from][to] = 0;}}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;H[from].resize(N, 0);for (auto x : G[from]) H[from][x] = 1, sum[x] -= A[from];}}else{H[from][to] = 1;}}};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 (H[x][c]) ans += A[x];cout << ans << "\n";}}}