結果
問題 | No.3025 Chocol∀te |
ユーザー |
|
提出日時 | 2025-02-14 22:10:21 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,976 ms / 2,000 ms |
コード長 | 2,852 bytes |
コンパイル時間 | 1,943 ms |
コンパイル使用メモリ | 179,572 KB |
実行使用メモリ | 34,012 KB |
最終ジャッジ日時 | 2025-02-14 22:11:53 |
合計ジャッジ時間 | 37,215 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 77 |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll = long long; #define all(a) (a).begin(), (a).end() #define pb push_back #define fi first #define se second mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count()); const ll MOD1000000007 = 1000000007; const ll MOD998244353 = 998244353; const ll MOD[3] = {999727999, 1070777777, 1000000007}; const ll LINF = 1LL << 60LL; const int IINF = (1 << 30) - 2; void solve(){ int n, m; cin >> n >> m; vector<unordered_set<int>> G(n); for(int i=0; i<m; i++){ int u, v; cin >> u >> v; u--; v--; G[u].insert(v); G[v].insert(u); } vector<ll> a(n); for(int i=0; i<n; i++) cin >> a[i]; vector<ll> sum(n, 0LL); int sq = (int)sqrt(n); set<int> hdeg; for(int v=0; v<n; v++) if(sq < (int)G[v].size()){ hdeg.insert(v); for(int to : G[v]) sum[v] += a[to]; } int q; cin >> q; while(q--){ int type; cin >> type; if(type == 1){ int u, v; cin >> u >> v; u--; v--; if(G[u].find(v) != G[u].end()){ // delete if(sq < (int)G[u].size()-1) sum[u] -= a[v]; if(sq < (int)G[v].size()-1) sum[v] -= a[u]; G[u].erase(v); G[v].erase(u); if((int)G[u].size()==sq) hdeg.erase(u); if((int)G[v].size()==sq) hdeg.erase(v); }else{ // insert if((int)G[u].size() == sq){ hdeg.insert(u); sum[u] = a[v]; for(int to : G[u]) sum[u] += a[to]; }else if(sq < (int)G[u].size()){ sum[u] += a[v]; } G[u].insert(v); if((int)G[v].size() == sq){ hdeg.insert(v); sum[v] = a[u]; for(int to : G[v]) sum[v] += a[to]; }else if(sq < (int)G[v].size()){ sum[v] += a[u]; } G[v].insert(u); } } if(type == 2){ int p; cin >> p; ll x; cin >> x; p--; for(int v : hdeg){ if(G[p].find(v) != G[p].end()){ sum[v] -= a[p]; sum[v] += x; } } a[p] = x; } if(type == 3){ int c; cin >> c; c--; if(sq < (int)G[c].size()){ cout << sum[c] << '\n'; }else{ ll ans = 0LL; for(int to : G[c]) ans += a[to]; cout << ans << '\n'; } } } } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int T=1; //cin >> T; while(T--) solve(); }