#P5465. [PKUSC2018] 星际穿越
[PKUSC2018] 星际穿越
Description
There are planets, numbered from 1 to . They are located in the same galaxy, which can be modeled as a number line. Each planet is a point on the number line. In particular, the coordinate of planet is .
At the beginning, due to technological limits, the residents of these planets could not communicate with each other, so they did not know each other existed. Now, these planets have independently developed tools for interstellar travel and interstellar communication. For planet , by sending a powerful signal, it successfully made contact with all planets with indices in (planet 1 did not send any signal). Any two planets that make contact will build a bidirectional portal. For two planets that have a portal between them, residents on can spend 1 unit of time to teleport to , and residents on can also spend 1 unit of time to teleport to . Let denote the minimum time needed to travel from planet to planet through a sequence of portals between planets.
Now there are interstellar merchants. The initial position of the -th merchant is , and his destination is one planet among , where it is guaranteed that . He will choose a planet in this interval uniformly at random (each planet has the same probability of being chosen as the destination), and then reach planet through portals, using the minimum possible time. The merchant wants to know the expected time he spends, i.e., compute $\frac{1}{r_i-l_i+1}{\sum_{y=l_i}^{r_i}{dist(x_i,y)}}$.
Input Format
The first line contains a positive integer , representing the number of planets.
The second line contains positive integers. The -th positive integer is , meaning that all planets with indices in the interval have already made contact with planet , and they can transmit to each other with cost 1. It is guaranteed that .
The third line contains a positive integer , representing the number of queries.
The next lines each contain three numbers , meaning: choose a planet uniformly at random in , and ask for the expected value of . It is guaranteed that .
Output Format
For each query, note that the answer must be a rational number, so output it in the form , requiring .
If the answer is an integer , output .
7
1 1 2 1 4 6
5
3 4 6
1 5 7
1 2 4
1 2 6
1 3 5
3/2
13/5
3/2
2/1
1/1
Hint
The undirected graph corresponding to the sample is as follows: 
For of the testdata, .
For another of the testdata, .
For another of the testdata, .
For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号