#P4243. [JSOI2009] 等差数列

[JSOI2009] 等差数列

Description

To check how well the students have learned, jyy assigns an exercise: given a sequence of length NN (1N100,0001 \leq N \leq 100,000), where initially the ii-th number is viv_i (viv_i is an integer, 100,000vi100,000-100,000 \leq v_i \leq 100,000), the students must modify some elements according to jyy’s operations. An operation has the form: A s t a b (s,t,a,bs, t, a, b are all integers, 1stN1 \leq s \leq t \leq N, 100,000a,b100,000-100,000 \leq a, b \leq 100,000). It means: over the interval [s,t][s, t], add an arithmetic progression with initial term aa and common difference bb. That is, viv_i becomes vi+a+b×(is)v_i + a + b \times (i - s) (for sits \leq i \leq t).

Amid their hectic calculations, the poor Martian students must also answer jyy’s questions at any time. A query has the form: B s t (s,ts, t are integers, 1stN1 \leq s \leq t \leq N), which asks for the minimum number of segments into which the current interval [s,t][s, t] can be partitioned so that each segment is an arithmetic progression. For example, 1 2 3 5 7 can be partitioned into 22 segments: 1 2 3 and 5 7. The answers to the queries must be computed and handed in as homework.

Although the total number of operations plus queries is only QQ (1Q100,0001 \leq Q \leq 100,000), jyy still finds this problem boring and troublesome. So he wants you to compute a standard answer for him.

Input Format

Line 11: one integer NN. Lines 2N+12 \cdots N + 1: each line contains one integer. Line i+1i + 1 gives viv_i.

Line N+2N + 2: one integer QQ. Lines N+3N+Q+2N + 3 \cdots N + Q + 2: each line describes an operation or a query, in the format described above, without quotes.

Output Format

Several lines, each containing one integer, representing the answer to a query. Output the answers in the same order as the queries appear in the input.

5
1
3
-1
-4
7
2
A 2 4 -1 5
B 1 5
2

Hint

Sample explanation:

The original sequence is 1 3 -1 -4 7. After the operation, the sequence becomes 1 2 3 5 7. As described above, the minimum number of segments is 22.

Constraints:

  • For 30%30\% of the testdata, N,Q5000N, Q \leq 5000.
  • For 100%100\% of the testdata, 1N,Q100,0001 \leq N, Q \leq 100,000.

Translated by ChatGPT 5