#abc319e. E - Bus Stops

E - Bus Stops

Score : 450450 points

问题描述

高桥最初位于自己的房子,并打算前往青木的家。

在两家房子之间有 NN 个公交车站,编号为 11NN,高桥可以通过以下方式在这些车站间移动:

  • 他可以在 XX 单位时间内步行从自己家走到第 11 号公交车站。
  • 对于每个 i=1,2,,N1i = 1, 2, \ldots, N-1,从第 ii 号公交车站出发的公交车在每个时间为 PiP_i 的倍数时发车,通过乘坐这辆公交车,他可以在 TiT_i 单位时间内到达第 (i+1)(i+1) 号公交车站。这里,条件保证了 1Pi81 \leq P_i \leq 8
  • 高桥可以在 YY 单位时间内从第 NN 号公交车站步行到青木的家。

对于每个 i=1,2,,Qi = 1, 2, \ldots, Q,处理以下查询请求。

当高桥在时间 qiq_i 离开自己家时,找出他最早能到达青木家的时间。

注意,如果他恰好在一辆公交车的发车时间到达某个公交车站,那么他可以乘坐那辆公交车。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Takahashi is initially at his house and is about to visit Aoki's house.

There are NN bus stops numbered 11 to NN between the two houses, and Takahashi can move between them in the following ways:

  • He can walk from his house to bus stop 11 in XX units of time.
  • For each i=1,2,,N1i = 1, 2, \ldots, N-1, a bus departs from bus stop ii at each time that is a multiple of PiP_i, and by taking this bus, he can get to bus stop (i+1)(i+1) in TiT_i units of time. Here, the constraints guarantee that 1Pi81 \leq P_i \leq 8.
  • Takahashi can walk from bus stop NN to Aoki's house in YY units of time.

For each i=1,2,,Qi = 1, 2, \ldots, Q, process the following query.

Find the earliest time that Takahashi can arrive at Aoki's house when he leaves his house at time qiq_i.

Note that if he arrives at a bus stop exactly at the departure time of a bus, he can take that bus.

Constraints

  • 2N1052 \leq N \leq 10^5
  • 1X,Y1091 \leq X, Y \leq 10^9
  • 1Pi81 \leq P_i \leq 8
  • 1Ti1091 \leq T_i \leq 10^9
  • 1Q2×1051 \leq Q \leq 2 \times 10^5
  • 0qi1090 \leq q_i \leq 10^9
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN XX YY

P1P_1 T1T_1

P2P_2 T2T_2

\vdots

PN1P_{N-1} TN1T_{N-1}

QQ

q1q_1

q2q_2

\vdots

qQq_Q

Output

Print QQ lines. For each i=1,2,,Qi = 1, 2, \ldots, Q, the ii-th line should contain the answer to the ii-th query.

Sample Input 1

4 2 3
5 4
6 6
3 1
7
13
0
710511029
136397527
763027379
644706927
447672230

Sample Output 1

34
22
710511052
136397548
763027402
644706946
447672250

For the first query, Takahashi can move as follows to arrive at Aoki's house at time 3434.

  • Leave his house at time 1313.
  • Walk from his house and arrive at bus stop 11 at time 1515.
  • Take the bus departing from bus stop 11 at time 1515 and arrive at bus stop 22 at time 1919.
  • Take the bus departing from bus stop 22 at time 2424 and arrive at bus stop 33 at time 3030.
  • Take the bus departing from bus stop 33 at time 3030 and arrive at bus stop 44 at time 3131.
  • Walk from bus stop 44 and arrive at Aoki's house at time 3434.

For the second query, Takahashi can move as follows and arrive at Aoki's house at time 2222.

  • Leave his house at time 00.
  • Walk from his house and arrive at bus stop 11 at time 22.
  • Take the bus departing from bus stop 11 at time 55 and arrive at bus stop 22 at time 99.
  • Take the bus departing from bus stop 22 at time 1212 and arrive at bus stop 33 at time 1818.
  • Take the bus departing from bus stop 33 at time 1818 and arrive at bus stop 44 at time 1919.
  • Walk from bus stop 44 and arrive at Aoki's house at time 2222.

update @ 2024/3/10 09:07:40