#P3085. [USACO23JAN] Tractor Paths P
[USACO23JAN] Tractor Paths P
题目描述
Note: The time limit for this problem is 4s, twice the default. The memory limit for this problem is 512MB, twice the default.
Farmer John has tractors, where the -th tractor can only be used within the inclusive interval . The tractor intervals have left endpoints and right endpoints . Some of the tractors are special.
Two tractors and are said to be adjacent if and intersect. Farmer John can transfer from one tractor to any adjacent tractor. A path between two tractors and consists of a sequence of transfers such that the first tractor in the sequence is , the last tractor in the sequence is , and every two consecutive tractors in the sequence are adjacent. It is guaranteed that there is a path between tractor and tractor . The length of a path is the number of transfers (or equivalently, the number of tractors within it minus one).
You are given queries, each specifying a pair of tractors and . For each query, output two integers:
- The length of any shortest path between tractor to tractor .
- The number of special tractors such that there exists at least one shortest path from tractor to tractor containing it.
输入格式
The first line contains and .
The next line contains a string of length consisting of Ls and Rs, representing the left and right endpoints in sorted order. It is guaranteed that for each proper prefix of this string, the number of Ls exceeds the number of Rs.
The next line contains a bit string of length , representing for each tractor whether it is special or not.
The next lines each contain two integers and , specifying a query.
输出格式
For each query, the two quantities separated by spaces.
题目大意
有 个区间,第 个区间为 。保证 且 。其中一部分区间是特殊的,输入会给定。
如果第 个区间和第 个区间相交,那么 之间有一条边。保证 联通。
给定 组询问,每次给定 满足 ,你需要回答 到 至少要经过多少条边,以及有多少个特殊区间对应的点,使得这个点可能在 到 的最短路径上。
。
输入格式
第一行包含两个整数 和 。
下一行包含一个长度为的字符串,由L和R组成,按排序顺序表示左端点和右端点。可以保证,对于该字符串的每个适当前缀,L的数量都超过R的数量。
下一行包含一个长度为的位字符串,表示每台拖拉机是否特殊。
接下来的行分别包含两个整数和,表示一个查询。
输出格式
对于每个查询,用空格分隔的两个输出。
8 10
LLLLRLLLLRRRRRRR
11011010
1 2
1 3
1 4
1 5
1 6
1 7
1 8
2 3
2 4
2 5
1 2
1 1
1 2
2 4
2 3
2 4
2 3
1 1
1 2
1 2
提示
Explanation for Sample 1
The tractor intervals, in order, are .
For the 4th query, there are three shortest paths between the 1st and 5th tractor: to to , to to , and to to . These shortest paths all have length .
Additionally, every tractor is part of one of the three shortest paths mentioned earlier, and since are special, there are special tractors such that there exists at least one shortest path from tractor to containing it.
Scoring
- Inputs :
- Inputs : There are at most special tractors.
- Inputs : No additional constraints.