結果

問題 No.3025 Chocol∀te
ユーザー Rubikun
提出日時 2025-02-14 23:43:03
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 872 ms / 2,000 ms
コード長 3,637 bytes
コンパイル時間 2,407 ms
コンパイル使用メモリ 213,752 KB
実行使用メモリ 9,028 KB
最終ジャッジ日時 2025-02-14 23:44:01
合計ジャッジ時間 38,782 ms
ジャッジサーバーID
(参考情報)
judge2 / judge7
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 77
権限があれば一括ダウンロードができます

ソースコード

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;

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

const int D=300;

bool miru[MAX];
bool iru[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;
    vii useE,ali;
    for(int i=0;i<M;i++){
        int a,b;cin>>a>>b;a--;b--;
        if(a>b) swap(a,b);
        useE.pb(mp(a,b));
        ali.pb(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};
            useE.pb(mp(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};
        }
    }
    mkunique(useE);
    for(auto s:ali){
        iru[lower_bound(all(useE),s)-useE.begin()]=true;
    }
    
    auto calc=[&](){
        for(int i=0;i<N;i++){
            ans[i]=0;
        }
        for(int i=0;i<si(useE);i++){
            if(iru[i]){
                auto [a,b]=useE[i];
                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){
            int e=lower_bound(all(useE),mp(a,b))-useE.begin();
            if(iru[e]){
                iru[e]=false;
                ans[a]-=A[b];
                ans[b]-=A[a];
            }else{
                iru[e]=true;
                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(binary_search(all(useE),mp(s,t))){
                    int po=lower_bound(all(useE),mp(s,t))-useE.begin();
                    if(iru[po]){
                        ans[x]-=A[a];
                        ans[x]+=b;
                    }
                }
            }
            A[a]=b;
        }
        if(t==3){
            cout<<ans[a]<<"\n";
        }
    }
}


0