#P2221. [HAOI2012] 高速公路

    ID: 1195 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2012河南线段树各省省选O2优化最大公约数,gcd期望

[HAOI2012] 高速公路

Description

The Y901 Expressway is an east–west chain consisting of n1n-1 road segments and nn toll stations. From west to east, we number the stations 11 to nn. Traveling from station ii to i+1i+1 (or from i+1i+1 to ii) costs viv_i. When the expressway was first built, all segments were free, i.e., all vi=0v_i = 0.

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 l,rl, r, choose two distinct stations aa and bb uniformly at random from stations ll through rr. What is the expected cost to travel from aa to bb?

Input Format

The first line contains two integers nn and mm, the number of toll stations and the total number of updates and queries.

Each of the next mm lines describes an update or a query and begins with a character opop.

  • If opop is C, then there follow three integers l,r,vl, r, v, meaning: increase by vv the toll on every road segment between the ll-th and the rr-th stations (i.e., all segments with indices ii where li<rl \le i < r).
  • If opop is Q, then there follow two integers l,rl, r. For the given l,rl, r, 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 aa, 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 1010 test points. The scale of each test point is as follows.

Test Point n=n= m=m=
1 1010
2 100100
3 10001000
4 1000010000
5 5000050000
6 6000060000
7 7000070000
8 8000080000
9 9000090000
10 100000100000

For all test points, it is guaranteed that 1n,m1051 \le n, m \le 10^5, op{C,Q}op \in \{\texttt{C}, \texttt{Q}\}, 1lrn1 \le l \le r \le n, 104v104-10^4 \le v \le 10^4, and at any time 0vi1040 \le v_i \le 10^4.

Translated by ChatGPT 5