因为公交车到达的时间为各个 的倍数,所以我们不用考虑具体的时间,只用考虑时间对各个 取模的值。可以发现,实际上只要考虑时间对 取模的值。
为方便处理,这里令 ,先预处理出发时间为 的答案 ,对于询问的具体时间 ,答案即为 。
放代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> pii;
int r[840];
int f(int n,int x){
if(n%x)return (n/x+1)*x;
else return n;
} // 找大于等于 n 且是 x 的倍数的最小整数
main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n,x,y; cin>>n>>x>>y;
vector<pii> a(n-1);
for(auto &[p,t]:a)cin>>p>>t;
for(int i=0;i<840;i++){
r[i]=i+x;
for(auto [p,t]:a)r[i]=f(r[i],p)+t;
r[i]+=y;
} // 模拟答案
int q; cin>>q;
while(q--){
int b; cin>>b;
cout<<r[b%840]+b/840*840<<'\n';
} // 处理询问
return 0;
}