QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#713687#4898. 基础图论练习题scallionsong0 0ms0kbC++146.1kb2024-11-05 20:17:422024-11-05 20:17:42

Judging History

你现在查看的是最新测评结果

  • [2024-11-05 20:17:42]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-11-05 20:17:42]
  • 提交

answer

bool M1;
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ull unsigned long long
#define LL __int128
#define db double
#define LD long double
#define Pii pair<int,int>
#define Pll pair<ll,ll>
#define Pull pair<ull,ull>
#define Pdb pair<db,db>
#define fir first
#define sec second
#define vec vector<int>
#define pb push_back
#define qlr cerr<<"qlr\n"
#define dyh cerr<<"dyh\n"
#define pc(x) __builtin_popcount(x)
#define uni(x,y) uniform_int_distribution<int>(x,y)(rng)
#define unl(x,y) uniform_int_distribution<ll>(x,y)(rng)
#define unr(x,y) uniform_real_distribution<double>(x,y)(rng)
#define F(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define UF(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define look_memory cerr<<'\n'<<abs(&M1-&M2)/1024.0/1024<<'\n'
#define look_time cerr<<'\n'<<clock()*1.0/CLOCKS_PER_SEC<<'\n'
mt19937 rng(time(0)^(*new int));
const int INF=0x3f3f3f3f;
const int Mod=998244353;
template<typename T>
inline void inc(T &a,T b){
	if(b<0) b+=Mod;
	a+=b;
	if(a>=Mod) a-=Mod;
}
template<typename T>
inline void dec(T &a,T b){
	if(b<0) b+=Mod;
	a-=b;
	if(a<0) a+=Mod;
}
template<typename T>
inline void muc(T &a,T b){
	a=a*b%Mod;
}
template<typename T>
inline bool chkmin(T &a,T b){
	if(a<=b) return false;
	a=b;
	return true;
}
template<typename T>
inline bool chkmax(T &a,T b){
	if(a>=b) return false;
	a=b;
	return true;
}
ll n,A,B,tot,ans;
ll ant[50010];
bool vis[50010];
Pll a[50010];
vector<ll> t[50010],g[100010];
gp_hash_table<ll,int> mp,id;
struct Edge{
    ll u,v,w,ty;
};
Edge b[1000010];
struct Dsu{
    #define N 200000
    int fa[N+10];
    void init(int n){
        F(i,0,n) fa[i]=i;
    }
    int fd(int x){
        return fa[x]==x?x:fa[x]=fd(fa[x]);
    }
    void merge(int x,int y){
        x=fd(x),y=fd(y);
        fa[x]=y;
    }
    #undef N
}dsu;
ll query1(ll x,vector<Pll> V){
    vis[V[0].sec]=1;
    if(V[0].fir>=x) return x;
    if((int)V.size()==1) return V[0].fir;
    ll t1=V[0].fir,t2=min(V[1].fir,x)/t1*t1;
    F(i,1,V.size()-1) V[i].fir-=t2;
    x-=t2;
    V.insert(lower_bound(V.begin()+1,V.end(),V[0]),V[0]);
    V.erase(V.begin());
    reverse(V.begin(),V.end());
    while(!V.empty()&&!V.back().fir) V.pop_back();
    reverse(V.begin(),V.end());
    return query1(x,V)+max(t1-x,0ll);
}
void query2(ll x,vector<ll> &V1,vector<ll> &V2){
    if(V1[0]>=x||(int)V1.size()==1){
        for(auto &i:V2) if(i>0) i%=V1[0];
        mp.clear();
        F(i,0,V2.size()-1){
            if(V2[i]<0) continue;
            if(mp.find(V2[i])!=mp.end()) dsu.merge(i,mp[V2[i]]);
            else mp[V2[i]]=i;
        }
        return;
    }
    ll t1=V1[0],t2=min(V1[1],x)/t1*t1;
    F(i,1,V1.size()-1) V1[i]-=t2;
    V1.insert(lower_bound(V1.begin()+1,V1.end(),V1[0]),V1[0]);
    V1.erase(V1.begin());
    reverse(V1.begin(),V1.end());
    while(!V1.empty()&&!V1.back()) V1.pop_back();
    reverse(V1.begin(),V1.end());
    x-=t2;
    if(x<t1){
        for(auto &i:V2) if(i>0) i=max(i-t2+t1,(i-1)%t1+1);
        mp.clear();
        F(i,0,V2.size()-1){
            if(V2[i]<0) continue;
            if(V2[i]<=x) V2[i]=V2[i];
            else if(V2[i]>t1) V2[i]-=t1;
            else{
                if(mp.find(V2[i])!=mp.end()) dsu.merge(i,mp[V2[i]]);
                else mp[V2[i]]=i;
                V2[i]=-1;
            }
        }
    }
    else for(auto &i:V2) if(i>0) i=max(i-t2,(i-1)%t1+1);
    bool fl=0;
    for(auto i:V2) if(i>0) fl=1;
    if(fl) query2(x,V1,V2);
}
void solve(int L,int R,vector<ll> V){
    if((int)V.size()<=1) return;
    while(L<R&&ant[R]==ant[R-1]) R--;
    if(L==R){
        if(L!=A+1) F(i,1,V.size()-1) b[++B]={V[i-1],V[i],a[L].sec,2};
        return;
    }
    int mid=(L+R)>>1;
    dsu.init(V.size()-1);
    vector<ll> f,V1,V2;
    
    V1=t[mid],V2=V;
    query2(n,V1,V2);
    V1.clear(),V2.clear();
    
    F(i,0,V.size()-1) f.pb(dsu.fd(i));
    F(i,0,V.size()-1) V1.pb(i);
    sort(V1.begin(),V1.end(),[&](ll cm1,ll cm2){return f[cm1]<f[cm2];});
    for(int i=0,j=0;i<(int)V1.size();i=j+1){
        j=i;
        while(j<(int)V1.size()-1&&f[V1[j+1]]==f[V1[i]]) j++;
        V2.clear();
        F(k,i,j) V2.pb(V[V1[k]]);
        solve(L,mid,V2);
    }
    V2.clear();
    F(i,0,V.size()-1) if(f[i]==i) V2.pb(V[i]);
    solve(mid+1,R,V2);
}
bool M2;
int main(){
	freopen("mst.in","r",stdin);
	freopen("mst.out","w",stdout);
	srand(time(0)^(*new int));
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    cin>>n>>A>>B;
    F(i,1,A) cin>>a[i].fir>>a[i].sec;
    F(i,1,B) cin>>b[i].u>>b[i].v>>b[i].w;
    F(i,1,B) b[i].u++,b[i].v++,b[i].ty=1;
    sort(a+1,a+A+1,[&](Pll cm1,Pll cm2){return cm1.sec<cm2.sec;});
    vector<Pll> V,tV;
    F(i,1,A){
        V.pb({a[i].fir,0});
        sort(V.begin(),V.end());
        F(j,0,V.size()-1) V[j].sec=j;
        F(j,0,V.size()-1) vis[j]=0;
        ant[i]=(n-query1(n,V))%Mod;
        tV.clear();
        F(j,0,V.size()-1) if(vis[j]) tV.pb(V[j]);
        V=tV;
        for(auto j:V) t[i].pb(j.fir);
    }
    F(i,1,A) ans=(ans+(ant[i]-ant[i-1])*a[i].sec)%Mod;

    vector<ll> rf;
    F(i,1,B) rf.pb(b[i].u),rf.pb(b[i].v);
    sort(rf.begin(),rf.end());
    rf.erase(unique(rf.begin(),rf.end()),rf.end());
    F(i,0,rf.size()-1) id[rf[i]]=i;

//	dsu.init(1);
//	query2(n,{8,11},{15,17});
//	F(i,0,1) cout<<dsu.fd(i)<<' ';

    solve(1,A+1,rf);

    sort(b+1,b+B+1,[&](Edge cm1,Edge cm2){return cm1.w<cm2.w;});
    
    dsu.init(rf.size()-1);
    F(i,1,B){
        if(b[i].ty==1) continue;
        ll u=id[b[i].u],v=id[b[i].v],w=b[i].w;
        if(dsu.fd(u)==dsu.fd(v)) continue;
        dsu.merge(u,v);
        dec(ans,w);
    }
    dsu.init(rf.size()-1);
    F(i,1,B){
        ll u=id[b[i].u],v=id[b[i].v],w=b[i].w;
        if(dsu.fd(u)==dsu.fd(v)) continue;
        dsu.merge(u,v);
        inc(ans,w);
    }
    ans=(ans%Mod+Mod)%Mod;
    cout<<ans;
	look_memory;
	look_time;
	return 0;
}
/*
g++ D2.cpp -o D2 -std=c++14 -O2&&./D2

20 3 2
11 2
8 0
19 0
14 0 3
12 16 1

*/

詳細信息

Subtask #1:

score: 0
Dangerous Syscalls

Test #1:

score: 0
Dangerous Syscalls

input:

161199 9 46510
147335 540442844
159493 801351455
149342 821625305
128476 843250712
95524 275754315
139315 106523502
93575 680460786
155498 328812257
146020 410466645
79992 141967 50596784
152210 68644 268349216
72549 96959 42994091
93869 27394 945120577
2909 81886 270684270
12735 35026 871917997
974...

output:


result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Dangerous Syscalls

Test #11:

score: 0
Dangerous Syscalls

input:

569435269457904707 2 0
490445920091092693 772271583
144842828305643603 609043885

output:


result:


Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Dangerous Syscalls

Test #31:

score: 0
Dangerous Syscalls

input:

755526150476311190 942 0
492334667739348527 1
755523898623296976 1
532486636690994793 1
755526150476030559 1
755526150476249097 1
502164090270592200 1
657422656495814703 1
487200614853438190 1
311037325561173142 1
755526150475651155 1
125287404340238660 1
755524914808674090 1
755526150476177007 1
75...

output:


result:


Subtask #6:

score: 0
Skipped

Dependency #3:

0%

Subtask #7:

score: 0
Skipped

Dependency #3:

0%

Subtask #8:

score: 0
Skipped

Dependency #5:

0%

Subtask #9:

score: 0
Skipped

Dependency #1:

0%