萌新刚学OI 求助6pts

P6348 [PA2011] Journeys

cat_lover1 @ 2024-06-23 21:50:25

#include<bits/stdc++.h>
using namespace std;
#define il inline
const int N=5e5,M=1e5,Siz=N*8+2*M+10;
int n,m,S,X;
vector<pair<int,bool>> G[Siz];
#define Ad(u,v,w) G[u].emplace_back(v,bool(w))
int t[Siz];
void Dijkstra(int s){
  static int d[Siz];
  bitset<Siz> vis;
  deque<int> q;
  memset(d,0x3f,n*4+m<<3);
  d[s]=0,q.push_back(s);
  for(int u; !q.empty();){
    u=q.front(),q.pop_front();
    if(vis[u]) continue; vis[u]=1;
    for(auto[v,w]:G[u]) 
      if(d[v]>d[u]+w) d[v]=d[u]+w,w?q.push_back(v):(q.push_front(v));
  }
  for(int i=1;i<=n;++i) 
    cout<<d[t[i]]<<'\n';
}
#define tr int h,int l,int r
#define ls h*2
#define rs ls|1
#define H X+h
#define Ls X+ls
#define Rs Ls+1
#define mid (l+r>>1)
#define lson ls,l,mid
#define rson rs,mid+1,r
il void build(tr){
  if(l==r) return void(t[l]=h);
  Ad(h,ls,0),Ad(h,rs,0);
  Ad(Ls,H,0),Ad(Rs,H,0);
  build(lson),build(rson);
}
il void update(tr,int x,int y,int z,bool o){
  if(x<=l&&r<=y) 
    return o?Ad(z,h,0),void(Ad(H,z+1,1))
           :(Ad(H,z,1),void(Ad(z+1,h,0)));
  if(x<=mid) update(lson,x,y,z,o);
  if(y>mid) update(rson,x,y,z,o);
}
main(){
  cin>>n>>m>>S,X=n*4;
  build(1,1,n);
  for(int i=1;i<=n;++i) 
    Ad(t[i],t[i]+X,0),Ad(t[i]+X,t[i],0);
  for(int a,b,c,d,i=0;i<m;++i){
    cin>>a>>b>>c>>d;
    update(1,1,n,a,b,X*2+i,1);
    update(1,1,n,c,d,X*2+i,0);
  }
  Dijkstra(X+t[S]);
}

by Betrayer_of_love @ 2024-06-23 21:54:42

@cat_lover1 你真萌新???紫题开切!!!


by cat_lover1 @ 2024-06-23 21:56:37

@SiuuuCR7 才6分一下午


by cat_lover1 @ 2024-06-23 21:56:51

求助大佬qwq


by Betrayer_of_love @ 2024-06-23 21:58:26

@cat_lover1 我只是六年级小蒟蒻


by Betrayer_of_love @ 2024-06-23 22:00:30

@cat_lover1 我可以看看,但是可能修改不了代码


by _FJqwq @ 2024-06-23 22:48:00

@cat_lover1

hack:

5 3 1
3 3 1 5
4 4 1 5
5 5 3 4

by _FJqwq @ 2024-06-23 22:52:12

in:

4 2 1
2 2 1 4
3 3 1 4

out:

0 1 1 1

ans:

0 1 1 2

by cat_lover1 @ 2024-06-23 23:30:57

@_FJqwq thx!


|