Stores of k types each occupy a point and an open year interval; for each (location, year) query, report the maximum over types of the distance to the nearest open store of that type, or -1 if some type is missing.
Hard9Segment treeBinary searchSortingDivide and conquerNo attempts yetTime limit5sMemory limit1024 MBWu-Fu Street is a perfectly straight street. It is described as a one-dimensional number line, so every building on it sits at a single number. Xiao-Ming the time traveler knows every store that opened, is open, or will open on the street: there are n stores of k types. Store i is given by four integers xi, ti, ai, bi, meaning the location of the store, the type of the store, the year its business starts, and the year its business ends. Store i is open in year y when ai≤y≤bi.
Xiao-Ming wants to pick a year and a location on Wu-Fu Street to live in, and he narrowed his preference list to q pairs of a location and a year. Pair i is given by two integers li, yi. He rates a pair by its inconvenience index, the inaccessibility of the store type that is hardest to reach. The inaccessibility of type t for a pair is the distance from the location to the nearest type-t store that is open in that year, so the inconvenience index is the largest of those distances over all k types. In some years Wu-Fu Street does not carry all k types. The inconvenience index of such a pair is −1.
Find the inconvenience index of every pair.
The first line contains three integers n, k, q: the number of stores, the number of types, and the number of queries (1≤n,q≤3×105, 1≤k≤n).
Each of the next n lines describes one store with four integers xi, ti, ai, bi (1≤xi,ai,bi≤108, 1≤ti≤k, ai≤bi).
Each of the next q lines contains one query, two integers li and yi (1≤li,yi≤108).
Print q integers, one per line, in the order the queries are given. The i-th of them is the inconvenience index of the i-th query.
The first sample has four stores, two types, and four queries.
The second sample has two stores, one type, and three queries. Both stores are at location 1, and every query asks about location 1. At least one store is open in the first two queries, so the answer is 0. Both stores are closed in the third query, so the answer is −1.
The third sample has one store and one query. The distance between the two locations is 99999999.