1020A.md (2372B)
1 Source: https://codeforces.com/problemset/problem/1020/A 2 3 A. New Building for SIS 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 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. 22 23 The building consists of *n* towers, *h* floors each, where the towers are labeled from 1 to *n*, the floors are labeled from 1 to *h*. There is a passage between any two adjacent towers (two towers *i* and *i* + 1 for all *i*: 1 ≤ *i* ≤ *n* - 1) on every floor *x*, where *a* ≤ *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. 24 25  26 27 The picture illustrates the first example. 28 29 You have given *k* pairs of locations (*t**a*, *f**a*), (*t**b*, *f**b*): floor *f**a* of tower *t**a* and floor *f**b* of tower *t**b*. For each pair you need to determine the minimum walking time between these locations. 30 31 Input 32 33 The first line of the input contains following integers: 34 35 * *n*: the number of towers in the building (1 ≤ *n* ≤ 108), 36 * *h*: the number of floors in each tower (1 ≤ *h* ≤ 108), 37 * *a* and *b*: the lowest and highest floor where it's possible to move between adjacent towers (1 ≤ *a* ≤ *b* ≤ *h*), 38 * *k*: total number of queries (1 ≤ *k* ≤ 104). 39 40 Next *k* lines contain description of the queries. Each description consists of four integers *t**a*, *f**a*, *t**b*, *f**b* (1 ≤ *t**a*, *t**b* ≤ *n*, 1 ≤ *f**a*, *f**b* ≤ *h*). This corresponds to a query to find the minimum travel time between *f**a*-th floor of the *t**a*-th tower and *f**b*-th floor of the *t**b*-th tower. 41 42 Output 43 44 For each query print a single integer: the minimum walking time between the locations in minutes. 45 46 Example 47 48 Input 49 50 ``` 51 3 6 2 3 3 52 1 2 1 3 53 1 4 3 4 54 1 2 2 3 55 ``` 56 57 Output 58 59 ``` 60 1 61 4 62 2 63 ```