D题求Hack,通过70%,最终结果是WA

#include<bits/stdc++.h>
#include<bits/extc++.h>
#define IOS std::ios::sync_with_stdio(false);std::cin.tie(nullptr);std::cout.tie(nullptr);
#define all(x) (x).begin(),(x).end()
#define quchong(x) (x).erase(unique(all(x)),(x).end())
#define Yes(x,y) cout<<((x)?"Yes":"No")<<y
#define yes(x,y) cout<<((x)?"yes":"no")<<y
#define YES(x,y) cout<<((x)?"YES":"NO")<<y
#define ls ((u)<<1)
#define rs ((u)<<1|1)
#define mid (((l)+(r))>>1)
#define lowbit(x) ((x)&(-(x)))
#define itn int
#define asn ans
#define reisze resize
#define pdd pair<double,double>
#define pll pair<LL,LL>
#define pii pair<int,int>
#define tll tuple<LL,LL,LL>
#define tii tuple<int,int,int>
#define plll pair<LLL,LLL>
#define ULL unsigned long long
#define LL long long
#define LLL __int128
#define ld long double
#define ui64 uint64_t
#define ui32 uint32_t
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using RBTree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T>
T fang(const T& a){
    return a*a;
}
template<typename T,typename Q>
bool chmax(T& u1,T& u2,const Q& v){
    if(v>u1) { u2 = u1, u1 = v;return true;}
    if(v>u2){u2=v;return true;}
    return false;
}
template<typename T,typename Q>
bool chmin(T& u1,T& u2,const Q& v){
    if(v<u1) { u2 = u1, u1 = v;return true;}
    if(v<u2){u2=v;return true;}
    return false;
}
template<typename T,typename Q>
bool chmin(T& a,const Q& b){
    return a > b && (a = b, true);
}
template<typename T,typename Q>
bool chmax(T& a,const Q& b){
    return a<b&&(a=b,true);
}
template<typename t1,typename t2>
istream& operator>>(istream& in,pair<t1,t2>& pa){
    in>>pa.first>>pa.second;
    return in;
}
template<typename t1,typename t2>
ostream& operator<<(ostream& out,const pair<t1,t2>& pa){
    out<<pa.first<<' '<<pa.second;
    return out;
}
template<typename T>
istream& operator>>(istream& in,vector<T>& arr){
    for(auto& v:arr)in>>v;
    return in;
}
template<typename T>
ostream& operator<<(ostream& out,const vector<T>& arr){
    for(auto& v:arr)out<<v<<' ';
    return out;
}
int rand(int l,int r){
    static mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
    return uniform_int_distribution<int>(l, r)(rng);
}
const ld eps=1e-9;
const int NN=4005;
const int SIZ=1e7;
const LL inf=1e16;
LL mod=998244353;
struct P{
    int x,y;
    LL w;
};
vector<P> tr[NN*4];
int q;
void build(int u,int l,int r){
    tr[u].clear();
    if(l==r)return;
}
void _change(int u, int l, int r, int L, int R, P ed){
    if(L<=l&&R>=r){
        tr[u].emplace_back(ed);
        return;
    }
    if(L<=mid)_change(ls, l, mid, L, R, ed);
    if(R>mid)_change(rs, mid + 1, r, L, R, ed);
}
set<int> qu;
vector<LL> ans;
void _insert(int u, int l, int r, int p){
    if(l==r){
        qu.insert(u);
        return;
    }
    p<=mid ? _insert(ls, l, mid, p) : _insert(rs, mid + 1, r, p);
}
void insert(int p){
    _insert(1,1,q,p);
}
void change(int L,int R,P ed){
    _change(1,1,q,L,R,ed);
}
int n;
void dfs(int u,int l,int r,vector<vector<LL>> dp){
    for(auto [x,y,w]:tr[u]){
        if(dp[x][y]<=w)continue;
        chmin(dp[x][y],w);
        dp[y][x]=dp[x][y];
        for(int i=1;i<=n;i++)chmin(dp[i][x],dp[i][y]+dp[y][x]),dp[x][i]=dp[i][x];
        for(int i=1;i<=n;i++)chmin(dp[i][y],dp[i][x]+dp[x][y]),dp[y][i]=dp[i][y];
        for(int i=1;i<=n;i++)for(int j=1;j<=n;j++){
                chmin(dp[i][j],min(dp[i][y]+dp[y][j],dp[i][x]+dp[x][j]));
                dp[j][i]=dp[i][j];
            }
    }
    if(l==r){
        if(qu.contains(u)){
            LL res=0;
            for(int i=1;i<=n;i++)for(int j=1;j<=n;j++){
                assert(dp[i][j]==dp[j][i]);
                if(dp[i][j]<inf)res+=dp[i][j]%mod,res%=mod;
            }
            ans.emplace_back(res);
        }
    }else{
        dfs(ls,l,mid,dp);
        dfs(rs,mid+1,r,dp);
    }
}
void solve(){
    cin>>n;
    int m;
    cin>>m;
    cin>>q;
    qu.clear();
    ans.clear();
    int id=m;
    map<int,pair<int,P>> M;
    for(int i=1;i<=m;i++){
        int x,y;
        LL w;
        cin>>x>>y>>w;
        M[i]={1,{x,y,w}};
    }
    build(1,1,q);
    for(int i=1;i<=q;i++){
        int op;
        cin>>op;
        if(op==1){
            int x,y;
            LL w;
            cin>>x>>y>>w;
            id++;
            M[id]={i,{x,y,w}};
        }else if(op==2){
            int k;
            cin>>k;
            auto it=M[k];
            change(it.first,i,it.second);
            M.erase(k);
        }else{
            insert(i);
        }
    }
    for(auto& [_,it]:M){
        change(it.first,q,it.second);
    }
    vector<vector<LL>> dp(n+1,vector<LL>(n+1));
    for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(i!=j)dp[i][j]=inf;
    dfs(1,1,q,dp);
    for(LL v:ans)cout<<v<<'\n';
}
signed main(){
    IOS;
    int _;
    cin>>_;
    while(_--)solve();
}

全部评论

相关推荐

今天 14:30
中南大学
点赞 评论 收藏
分享
06-25 16:25
梧州学院 Java
愿汐_:项目介绍那么长,然而你做了啥就一句话?
点赞 评论 收藏
分享
温州头等大孝子:你们的确很幸福,但是有一个小问题:谁问你了?我的意思是,谁在意?我告诉你,根本没人问你,在我们之中0人问了你,我把所有问你的人都请来 party 了,到场人数是0个人,誰问你了?WHO ASKED?谁问汝矣?誰があなたに聞きましたか?누가 물어봤어?我爬上了珠穆朗玛峰也没找到谁问你了,我刚刚潜入了世界上最大的射电望远镜也没开到那个问你的人的盒,在找到谁问你之前我连癌症的解药都发明了出来,我开了最大距离渲染也没找到谁问你了我活在这个被辐射蹂躏了多年的破碎世界的坟墓里目睹全球核战争把人类文明毁灭也没见到谁问你了
字节跳动开奖366人在聊
点赞 评论 收藏
分享
08-07 11:43
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务