CF925A.Stairs and Elevators

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

In the year of 30XX30XX participants of some world programming championship live in a single large hotel. The hotel has nn floors. Each floor has mm sections with a single corridor connecting all of them. The sections are enumerated from 11 to mm along the corridor, and all sections with equal numbers on different floors are located exactly one above the other. Thus, the hotel can be represented as a rectangle of height nn and width mm. We can denote sections with pairs of integers (i,j)(i, j), where ii is the floor, and jj is the section number on the floor.

The guests can walk along the corridor on each floor, use stairs and elevators. Each stairs or elevator occupies all sections (1,x)(1, x), (2,x)(2, x), …\ldots, (n,x)(n, x) for some xx between 11 and mm. All sections not occupied with stairs or elevators contain guest rooms. It takes one time unit to move between neighboring sections on the same floor or to move one floor up or down using stairs. It takes one time unit to move up to vv floors in any direction using an elevator. You can assume you don't have to wait for an elevator, and the time needed to enter or exit an elevator is negligible.

You are to process qq queries. Each query is a question "what is the minimum time needed to go from a room in section (x1,y1)(x_1, y_1) to a room in section (x2,y2)(x_2, y_2)?"

在 30XX30XX 年,某世界编程锦标赛的参赛者们全部居住在一家大型酒店中。该酒店共有 nn 层楼,每层楼有 mm 个区域,所有区域沿一条公共走廊依次排列。各区域沿走廊编号为 11 至 mm;不同楼层上编号相同的区域恰好上下对齐。因此,整座酒店可表示为一个高为 nn、宽为 mm 的矩形。我们用二元组 (i,j)(i, j) 表示某个区域,其中 ii 为楼层号,jj 为该楼层上的区域编号。

宾客可在同一楼层的走廊中自由行走,也可使用楼梯或电梯。每部楼梯或电梯占据所有形如 (1,x),(2,x),…,(n,x)(1, x), (2, x), \ldots, (n, x) 的区域,其中 xx 为 11 到 mm 之间的某个整数。所有未被楼梯或电梯占据的区域均为客房。在同一楼层中从一个区域移动到相邻区域,或通过楼梯上下一层楼,均需耗时 11 个时间单位。而使用电梯上下最多 vv 层楼(任意方向)也仅需 11 个时间单位。你可以假设无需等待电梯,且进出电梯所需时间可忽略不计。

你需要处理 qq 个查询。每个查询的形式为:“从区域 (x1,y1)(x_1, y_1) 内的一间客房出发,到达区域 (x2,y2)(x_2, y_2) 内的一间客房,所需的最短时间是多少?”

输入格式

The first line contains five integers n,m,cl,ce,vn, m, c_l, c_e, v (2≤n,m≤1082 \leq n, m \leq 10^8, 0≤cl,ce≤1050 \leq c_l, c_e \leq 10^5, 1≤cl+ce≤m−11 \leq c_l + c_e \leq m - 1, 1≤v≤n−11 \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 (1≤li≤m1 \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 (1≤q≤1051 \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 (1≤x1,x2≤n1 \leq x_1, x_2 \leq n, 1≤y1,y2≤m1 \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.

第一行包含五个整数 n,m,cl,ce,vn, m, c_l, c_e, v(2≤n,m≤1082 \leq n, m \leq 10^8,0≤cl,ce≤1050 \leq c_l, c_e \leq 10^5,1≤cl+ce≤m−11 \leq c_l + c_e \leq m - 1,1≤v≤n−11 \leq v \leq n - 1),分别表示楼层数、每层的房间数、楼梯数量、电梯数量以及电梯的最大运行速度。

第二行包含 clc_l 个严格递增的整数 l1,…,lcll_1, \ldots, l_{c_l}(1≤li≤m1 \leq l_i \leq m),表示各楼梯所在的位置。若 cl=0c_l = 0,则第二行为空行。

第三行包含 cec_e 个严格递增的整数 e1,…,ecee_1, \ldots, e_{c_e},以相同格式表示各电梯所在的位置。保证所有 lil_i 和 eie_i 互不相同。

第四行包含一个整数 qq(1≤q≤1051 \leq q \leq 10^5),表示查询次数。

接下来 qq 行描述各次查询。每行包含四个整数 x1,y1,x2,y2x_1, y_1, x_2, y_2(1≤x1,x2≤n1 \leq x_1, x_2 \leq n,1≤y1,y2≤m1 \leq y_1, y_2 \leq m),表示该次查询的起点与终点房间坐标。保证起点与终点房间不同,且这两个房间均为客房(即 y1y_1 和 y2y_2 均不等于任一 lil_i 或 eie_i)。

输出格式

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

输出 qq 个整数,每个整数占一行——即各查询的答案。

输入输出样例

  • 输入#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.

在第一次查询中,最优方案是用 4 个时间单位到达第 5 区域的电梯,再用 2 个时间单位乘坐电梯到达第 5 层,最后再用 1 个时间单位到达目的地。

在第二次查询中,使用电梯仍是最优方案;但在第三次查询中,在第 2 区域使用楼梯更优。

输入解题思路,AI测评打分。不知道怎么写?

首页