#P4635. [SHOI2011] 改进代码
[SHOI2011] 改进代码
Description
PP wrote two pieces of code to operate on an array.
For Pascal users, the two procedures are as follows:
procedure operate1(l, r, c : longint);
var
i : longint;
begin
for i := l to r do
a[i] := (a[i] + c) mod p;
end;
procedure operate2(l, r : longint);
var
i, cnt : longint;
begin
cnt := 0;
for i := l to r - 1 do
if a[i] > a[i + 1]
then cnt := cnt + 1;
writeln(cnt);
end;
For C / C++ users, the two functions are as follows:
void operate1(int l, int r, int c)
{
int i;
for (i = l; i <= r; ++i)
a[i] = (a[i] + c) % p;
}
void operate2(int l, int r)
{
int i, cnt = 0;
for (i = l; i < r; ++i)
if (a[i] > a[i + 1])
++ cnt;
printf("%d\n", cnt);
}
Then, the main program can operate on the array by calling these two subroutines. The following is sample code.
For Pascal users, the code is:
begin
operate1(1, 4, 3);
operate1(4, 7, 4);
operate2(1, 7);
end.
For C / C++ users, the code is:
int main()
{
operate1(1, 4, 3);
operate1(4, 7, 4);
operate2(1, 7);
}
However, QQ thinks PP’s program is too slow, and he wants you to optimize PP’s code. That is, given a main program that contains only two kinds of statements, operate1 and operate2, and the initial values of the array before running, please compute the output of the program.
Input Format
The first line contains integers . Here, is the upper bound of in the operations, is the number of statements in the main program, and is the value of the constant in the program.
In the next lines, each line contains one integer, which are the initial values of in order. The input guarantees that these values are all within .
In the next lines, each line describes one line of code in the main program. Each line has one of the following two formats:
1 l r c: represents the statementoperate1(l, r, c);.2 l r: represents the statementoperate2(l, r);.
Output Format
Output the output produced by the program corresponding to the given input.
7 3 7
2
5
3
0
3
1
2
1 1 4 3
1 4 7 4
2 1 7
2
5 5 2
1
0
0
1
0
2 1 4
2 1 5
1 3 5 1
2 1 4
2 1 3
1
2
2
1
Hint
Constraints and notes
Test point : .
Test points : , , , , .
Test point : .
Test points : , and for all operate1 parameters, .
Test points : .
It is guaranteed that , , .
Translated by ChatGPT 5
京公网安备 11011102002149号