#P2221. [HAOI2012] 高速公路
[HAOI2012] 高速公路
Description
The Y901 Expressway is an east–west chain consisting of road segments and toll stations. From west to east, we number the stations to . Traveling from station to (or from to ) costs . When the expressway was first built, all segments were free, i.e., all .
The authorities will, from time to time, adjust the toll standards for consecutive segments, increasing or decreasing them according to policy.
A bored student, "Xiao A" (pinyin: Xiao A), likes to ponder quirky questions. While driving on this expressway, he wondered: for given , choose two distinct stations and uniformly at random from stations through . What is the expected cost to travel from to ?
Input Format
The first line contains two integers and , the number of toll stations and the total number of updates and queries.
Each of the next lines describes an update or a query and begins with a character .
- If is
C, then there follow three integers , meaning: increase by the toll on every road segment between the -th and the -th stations (i.e., all segments with indices where ). - If is
Q, then there follow two integers . For the given , answer Xiao A’s question.
Output Format
For each query, output a single line containing the answer as a reduced fraction.
If the answer is an integer , output a/1.
4 5
C 1 4 2
C 1 2 -1
Q 1 2
Q 2 4
Q 1 4
1/1
8/3
17/6
Hint
Constraints
There are test points. The scale of each test point is as follows.
| Test Point | ||
|---|---|---|
| 1 | ||
| 2 | ||
| 3 | ||
| 4 | ||
| 5 | ||
| 6 | ||
| 7 | ||
| 8 | ||
| 9 | ||
| 10 | ||
For all test points, it is guaranteed that , , , , and at any time .
Translated by ChatGPT 5
京公网安备 11011102002149号