CF925A.Stairs and Elevators
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The first line contains five integers n,m,cl,ce,v ( 2≤n,m≤108 , 0≤cl,ce≤105 , 1≤cl+ce≤m−1 , 1≤v≤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 cl integers l1,…,lcl in increasing order ( 1≤li≤m ), denoting the positions of the stairs. If cl=0 , the second line is empty.
The third line contains ce integers e1,…,ece in increasing order, denoting the elevators positions in the same format. It is guaranteed that all integers li and ei are distinct.
The fourth line contains a single integer q ( 1≤q≤105 ) — the number of queries.
The next q lines describe queries. Each of these lines contains four integers x1,y1,x2,y2 ( 1≤x1,x2≤n , 1≤y1,y2≤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. y1 and y2 are not among li and ei .
输入格式
Print q 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.