結果
| 問題 |
No.3025 Chocol∀te
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-02-15 05:12:22 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,228 ms / 2,000 ms |
| コード長 | 2,721 bytes |
| コンパイル時間 | 1,953 ms |
| コンパイル使用メモリ | 180,180 KB |
| 実行使用メモリ | 34,108 KB |
| 最終ジャッジ日時 | 2025-02-15 05:12:55 |
| 合計ジャッジ時間 | 29,566 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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];
int q; cin >> q;
vector<ll> sum(n, 0LL);
int sq = (int)sqrt(m+q);
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];
}
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] = 0LL;
for(int to : G[u]) sum[u] += a[to];
}
sum[u] += a[v];
G[u].insert(v);
if((int)G[v].size() == sq){
hdeg.insert(v);
sum[v] = 0LL;
for(int to : G[v]) sum[v] += a[to];
}
sum[v] += a[u];
G[v].insert(u);
}
}
if(type == 2){
int p; cin >> p; p--;
ll x; cin >> x;
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();
}