P4678 [BalticOI 2005] Bus Trip 题解
![P4678 [BalticOI 2005] Bus Trip 题解](https://img2023.cnblogs.com/blog/3297921/202310/3297921-20231026205911993-123797369.png)
P4678 [BalticOI 2005] Bus Trip 题解(RE:题解再改造!!)
贴码
#include<bits/stdc++.h>
#define MAXN 500010
using namespace std;
//ifstream is("trip.in",ios::in);
//ofstream os("trip.out",ios::out);
//#define cin is
//#define cout os
int n,m,p,t,tote,dist[MAXN],ans[MAXN];
struct Bus {
int x,t,idx,dist;
}b[MAXN];
void build(int x,int t,int idx,int dist){
b[++tote]={x,t,idx,dist};
}
bool cmp(const Bus &x,const Bus &y){
return x.t==y.t?x.dist>y.dist:x.t<y.t;
}
int main(){
ios::sync_with_stdio(0);
cin>>n>>m>>p>>t;
for(int i=1,s,t,a,b,c,d;i<=m;i++){
cin>>s>>t>>a>>b>>c>>d;
build(s,a,i,0);
build(t,d,i,c-b);
}
build(n+1,t,0,-0x3f3f3f3f);
sort(b+1,b+tote+1,cmp);
memset(dist,250,sizeof(dist));
dist[1]=0;
for(int i=1;i<=tote;i++){
if(b[i].x==n+1) break;
if(!b[i].dist) ans[b[i].idx]=dist[b[i].x];
else