Legacy
Subject to the effect
Maintain a map, you can at any time:
1, an edge is added \ ((u, v) \ )
2, a set of edges added \ ((u, {l ~ r}) \)
3, a set of edges added \ (({l ~ r} , u) \)
All sides are set above the weights, from a certain point and finally find the shortest path to all points.
Solution
If violence will be built side + dij T's
So we consider the tree line side by Optimized
We have established two tree line, a one, not even to his father side, the other side from even a b son from father to son, and then leaves b corresponds to a leaf edges even, uniform weights are 0
Then if a single point to single point even edges, it leaves from a leaf connected to the b side is connected
Even if the single-point interval, it is even interval from the side of b to a son
Point is connected to a single section from a section connected to the side of the son b
The last run again dij enough.
In addition, SPFA will be T
code:
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct qwq{
int v,w;
int nxt;
}edge[4000010];
int cnt=-1;
int head[1000010];
void add(int u,int v,int w){
edge[++cnt].nxt=head[u];
edge[cnt].v=v;
edge[cnt].w=w;
head[u]=cnt;
}
int numa[1000010],numb[1000010];
int re1[1000010],re2[1000010];
int tot;
void builda(int o,int l,int r){
numa[o]=++tot;
if(l==r){
re1[l]=tot;
return;
}
int mid=(l+r)/2;
builda(o*2,l,mid);
builda(o*2+1,mid+1,r);
add(numa[o*2],numa[o],0);
add(numa[o*2+1],numa[o],0);
}
void buildb(int o,int l,int r){
numb[o]=++tot;
if(l==r){
re2[l]=tot;
add(re2[l],re1[l],0);
return;
}
int mid=(l+r)/2;
buildb(o*2,l,mid);
buildb(o*2+1,mid+1,r);
add(numb[o],numb[o*2],0);
add(numb[o],numb[o*2+1],0);
}
void update1(int o,int l,int r,int L,int R,int v,int w){
if(L<=l&&r<=R){
add(numa[o],v,w);
return;
}
int mid=(l+r)/2;
if(L<=mid)update1(o*2,l,mid,L,R,v,w);
if(mid<R)update1(o*2+1,mid+1,r,L,R,v,w);
}
void update2(int o,int l,int r,int L,int R,int v,int w){
if(L<=l&&r<=R){
add(v,numb[o],w);
return;
}
int mid=(l+r)/2;
if(L<=mid)update2(o*2,l,mid,L,R,v,w);
if(mid<R)update2(o*2+1,mid+1,r,L,R,v,w);
}
int dis[1000010];
struct QAQ{
int v,w;
bool operator <(const QAQ& tmp)const{
return w>tmp.w;
}
};
void dijkstra(int s){
for(int i=1;i<=1000000;++i)dis[i]=100000000000000000ll;
dis[s]=0;
priority_queue<QAQ> q;
q.push((QAQ){s,0});
while(!q.empty()){
QAQ u=q.top();
q.pop();
int v=u.v,w=u.w;
if(w!=dis[v])continue;
for(int i=head[v];~i;i=edge[i].nxt){
int tv=edge[i].v,tw=edge[i].w;
if(dis[tv]>dis[v]+tw){
dis[tv]=dis[v]+tw;
q.push((QAQ){tv,dis[tv]});
}
}
}
}
signed main(){
memset(head,-1,sizeof(head));
int n,q,s;
scanf("%lld%lld%lld",&n,&q,&s);
builda(1,1,n);
buildb(1,1,n);
for(int i=1;i<=q;++i){
int opt;
scanf("%d",&opt);
if(opt==1){
int u,v,w;
scanf("%lld%lld%lld",&u,&v,&w);
add(re1[u],re2[v],w);
}
else if(opt==2){
int u,l,r,w;
scanf("%lld%lld%lld%lld",&u,&l,&r,&w);
update2(1,1,n,l,r,re1[u],w);
}
else {
int u,l,r,w;
scanf("%lld%lld%lld%lld",&u,&l,&r,&w);
update1(1,1,n,l,r,re2[u],w);
}
}
dijkstra(re1[s]);
for(int i=1;i<=n;++i){
printf("%lld ",dis[re1[i]]>10000000000000ll?-1:dis[re1[i]]);
}
}