CF1020A.New Building for SIS

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are looking at the floor plan of the Summer Informatics School's new building. You were tasked with SIS logistics, so you really care about travel time between different locations: it is important to know how long it would take to get from the lecture room to the canteen, or from the gym to the server room.

The building consists of nn towers, hh floors each, where the towers are labeled from 11 to nn , the floors are labeled from 11 to hh . There is a passage between any two adjacent towers (two towers ii and i+1i+1 for all ii : 1<=i<=n11<=i<=n-1 ) on every floor xx , where a<=x<=ba<=x<=b . It takes exactly one minute to walk between any two adjacent floors of a tower, as well as between any two adjacent towers, provided that there is a passage on that floor. It is not permitted to leave the building.

The picture illustrates the first example.

You have given kk pairs of locations (ta,fa)(t_{a},f_{a}) , (tb,fb)(t_{b},f_{b}) : floor faf_{a} of tower tat_{a} and floor fbf_{b} of tower tbt_{b} . For each pair you need to determine the minimum walking time between these locations.

输入格式

The first line of the input contains following integers:

  • nn : the number of towers in the building ( 1<=n<=1081<=n<=10^{8} ),
  • hh : the number of floors in each tower ( 1<=h<=1081<=h<=10^{8} ),
  • aa and bb : the lowest and highest floor where it's possible to move between adjacent towers ( 1<=a<=b<=h1<=a<=b<=h ),
  • kk : total number of queries ( 1<=k<=1041<=k<=10^{4} ).

Next kk lines contain description of the queries. Each description consists of four integers tat_{a} , faf_{a} , tbt_{b} , fbf_{b} ( 1<=ta,tb<=n1<=t_{a},t_{b}<=n , 1<=fa,fb<=h1<=f_{a},f_{b}<=h ). This corresponds to a query to find the minimum travel time between faf_{a} -th floor of the tat_{a} -th tower and fbf_{b} -th floor of the tbt_{b} -th tower.

输出格式

For each query print a single integer: the minimum walking time between the locations in minutes.

输入输出样例

  • 输入#1

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

    输出#1

    1
    4
    2
    
首页