CF925A.Stairs and Elevators

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The first line contains five integers n,m,cl,ce,vn, m, c_l, c_e, v ( 2n,m1082 \leq n, m \leq 10^8 , 0cl,ce1050 \leq c_l, c_e \leq 10^5 , 1cl+cem11 \leq c_l + c_e \leq m - 1 , 1vn11 \leq v \leq n - 1 ) — the number of floors and section on each floor, the number of stairs, the number of elevators and the maximum speed of an elevator, respectively.

The second line contains clc_l integers l1,,lcll_1, \ldots, l_{c_l} in increasing order ( 1lim1 \leq l_i \leq m ), denoting the positions of the stairs. If cl=0c_l = 0 , the second line is empty.

The third line contains cec_e integers e1,,ecee_1, \ldots, e_{c_e} in increasing order, denoting the elevators positions in the same format. It is guaranteed that all integers lil_i and eie_i are distinct.

The fourth line contains a single integer qq ( 1q1051 \leq q \leq 10^5 ) — the number of queries.

The next qq lines describe queries. Each of these lines contains four integers x1,y1,x2,y2x_1, y_1, x_2, y_2 ( 1x1,x2n1 \leq x_1, x_2 \leq n , 1y1,y2m1 \leq y_1, y_2 \leq m ) — the coordinates of starting and finishing sections for the query. It is guaranteed that the starting and finishing sections are distinct. It is also guaranteed that these sections contain guest rooms, i. e. y1y_1 and y2y_2 are not among lil_i and eie_i .

输入格式

Print qq integers, one per line — the answers for the queries.

输出格式

In the first query the optimal way is to go to the elevator in the 5-th section in four time units, use it to go to the fifth floor in two time units and go to the destination in one more time unit.

In the second query it is still optimal to use the elevator, but in the third query it is better to use the stairs in the section 2.

输入输出样例

  • 输入#1

    5 6 1 1 3
    2
    5
    3
    1 1 5 6
    1 3 5 4
    3 3 5 3
    

    输出#1

    7
    5
    4
    

说明/提示

In the first query the optimal way is to go to the elevator in the 5-th section in four time units, use it to go to the fifth floor in two time units and go to the destination in one more time unit.

In the second query it is still optimal to use the elevator, but in the third query it is better to use the stairs in the section 2.

首页