結果

問題 No.3025 Chocol∀te
ユーザー Rubikun
提出日時 2025-02-14 23:12:07
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 3,093 bytes
コンパイル時間 2,507 ms
コンパイル使用メモリ 208,712 KB
実行使用メモリ 27,336 KB
最終ジャッジ日時 2025-02-14 23:18:24
合計ジャッジ時間 172,459 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 32 TLE * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

#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=200;

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--;
        if(a>b) swap(a,b);
        SE.insert(mp(a,b));
    }
    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--;
            if(a>b) swap(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(auto [a,b]:SE){
            ans[a]+=A[b];
            ans[b]+=A[a];
        }
    };
    
    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==3){
                    miru[a]=true;
                }
            }
            for(int j=i;j<min(i+D,Q);j++){
                auto [t,a,b]=que[j];
                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));
                ans[a]-=A[b];
                ans[b]-=A[a];
            }else{
                SE.insert(mp(a,b));
                ans[a]+=A[b];
                ans[b]+=A[a];
            }
        }
        if(t==2){
            for(int x:use){
                int s=a,t=x;
                if(s>t) swap(s,t);
                if(SE.count(mp(s,t))){
                    ans[x]-=A[a];
                    ans[x]+=b;
                }
            }
            A[a]=b;
        }
        if(t==3){
            cout<<ans[a]<<"\n";
        }
    }
}


0