题解:P14418 [JOISC 2014] 巴士走读 / Bus
qdl66666666 · · 题解
排序 + 二分
题意
给定
JOI 君可以换乘公交车,只要前一辆到达当前站的时间
给定
做法
我们要求在时间
我们按到达时间
所以对于每一个点
对于每一条巴士路径,我们在
特别的,站点为起点的最晚出发时间就是每条从起点出发的巴士的出发时间。
Code
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e6 + 10;
template<typename TY>
inline void read(TY &s){
ll x = 0,f = 1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-') f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
s = x * f;
}
int n,m,q;
struct node{
int a,b,x,y;
}z[N];
bool cmp(node a,node b){
return a.y < b.y;
}
vector<int> ans[N],pos[N];
int main(){
read(n); read(m);
for(int i=1;i<=m;i++){
read(z[i].a); read(z[i].b); read(z[i].x); read(z[i].y);
}
sort(z+1,z+m+1,cmp);
for(int i=1;i<=n;i++) ans[i].push_back(-1),pos[i].push_back(0);
for(int i=1;i<=m;i++){
int a = z[i].a,b = z[i].b,x = z[i].x,y = z[i].y;
int maxn;
if(a == 1) maxn = x;
else maxn = ans[a][upper_bound(pos[a].begin(),pos[a].end(),x) - pos[a].begin() - 1];
if(maxn > ans[b][pos[b].size()-1]) ans[b].push_back(maxn),pos[b].push_back(y);
}
read(q);
int l = 0;
while(q--){
read(l);
cout << ans[n][upper_bound(pos[n].begin(),pos[n].end(),l) - pos[n].begin() - 1] << "\n";
}
return 0;
}