#P4243. [JSOI2009] 等差数列
[JSOI2009] 等差数列
Description
To check how well the students have learned, jyy assigns an exercise: given a sequence of length (), where initially the -th number is ( is an integer, ), the students must modify some elements according to jyy’s operations. An operation has the form: A s t a b ( are all integers, , ). It means: over the interval , add an arithmetic progression with initial term and common difference . That is, becomes (for ).
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 ( are integers, ), which asks for the minimum number of segments into which the current interval can be partitioned so that each segment is an arithmetic progression. For example, 1 2 3 5 7 can be partitioned into 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 (), jyy still finds this problem boring and troublesome. So he wants you to compute a standard answer for him.
Input Format
Line : one integer . Lines : each line contains one integer. Line gives .
Line : one integer . Lines : 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 .
Constraints:
- For of the testdata, .
- For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号