結果
問題 |
No.3025 Chocol∀te
|
ユーザー |
![]() |
提出日時 | 2025-02-14 21:56:22 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,947 bytes |
コンパイル時間 | 2,296 ms |
コンパイル使用メモリ | 213,516 KB |
実行使用メモリ | 57,692 KB |
最終ジャッジ日時 | 2025-02-14 22:01:03 |
合計ジャッジ時間 | 208,898 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 10 TLE * 67 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; } #define vi vector<int> #define vl vector<ll> #define vii vector<pair<int,int>> #define vll vector<pair<ll,ll>> #define vvi vector<vector<int>> #define vvl vector<vector<ll>> #define vvii vector<vector<pair<int,int>>> #define vvll vector<vector<pair<ll,ll>>> #define vst vector<string> #define pii pair<int,int> #define pll pair<ll,ll> #define pb push_back #define all(x) (x).begin(),(x).end() #define mkunique(x) sort(all(x));(x).erase(unique(all(x)),(x).end()) #define fi first #define se second #define mp make_pair #define si(x) int(x.size()) const int mod=998244353,MAX=300005,INF=15<<26; const int D=80; set<int> G[MAX]; bool miru[MAX]; int main(){ std::ifstream in("text.txt"); std::cin.rdbuf(in.rdbuf()); cin.tie(0); ios::sync_with_stdio(false); int N,M;cin>>N>>M; set<pii> SE; for(int i=0;i<M;i++){ int a,b;cin>>a>>b;a--;b--; G[a].insert(b); G[b].insert(a); SE.insert(mp(a,b)); SE.insert(mp(b,a)); } vl A(N),ans(N); for(int i=0;i<N;i++){ cin>>A[i]; } int Q;cin>>Q; vector<array<int,3>> que(Q); for(int i=0;i<Q;i++){ int t;cin>>t; if(t==1){ int a,b;cin>>a>>b;a--;b--; que[i]={1,a,b}; } if(t==2){ int a,b;cin>>a>>b;a--; que[i]={2,a,b}; } if(t==3){ int x;cin>>x;x--; que[i]={3,x,-1}; } } auto calc=[&](){ for(int i=0;i<N;i++){ ans[i]=0; } for(int i=0;i<N;i++){ for(int to:G[i]){ ans[i]+=A[to]; } } }; vi use; for(int i=0;i<Q;i++){ if(i%D==0){ calc(); use.clear(); for(int j=i;j<min(i+D,Q);j++){ auto [t,a,b]=que[j]; if(t==1){ miru[a]=true; miru[b]=true; } if(t==2){ miru[a]=true; } if(t==3){ miru[a]=true; } } for(int j=i;j<min(i+D,Q);j++){ auto [t,a,b]=que[j]; if(t==1){ if(miru[a]){ use.pb(a); miru[a]=false; } if(miru[b]){ use.pb(b); miru[b]=false; } } if(t==2){ if(miru[a]){ use.pb(a); miru[a]=false; } } if(t==3){ if(miru[a]){ use.pb(a); miru[a]=false; } } } } auto [t,a,b]=que[i]; if(t==1){ if(SE.count(mp(a,b))){ SE.erase(mp(a,b)); SE.erase(mp(b,a)); ans[a]-=A[b]; ans[b]-=A[a]; G[a].erase(b); G[b].erase(a); }else{ SE.insert(mp(a,b)); SE.insert(mp(b,a)); ans[a]+=A[b]; ans[b]+=A[a]; G[a].insert(b); G[b].insert(a); } } if(t==2){ for(int x:use){ if(G[x].count(a)){ ans[x]-=A[a]; ans[x]+=b; } } A[a]=b; } if(t==3){ cout<<ans[a]<<"\n"; } } }