#P6631. [ZJOI2020] 序列
[ZJOI2020] 序列
Description
Bob likes sequences.
There is a non-negative integer sequence of length . In each step, you may choose one of the following three operations to perform:
-
Choose an interval , and subtract from all numbers whose indices are in this interval.
-
Choose an interval , and subtract from all numbers in this interval whose indices are odd.
-
Choose an interval , and subtract from all numbers in this interval whose indices are even.
Find the minimum number of steps needed to make all numbers in the sequence become .
Input Format
The first line contains an integer , which denotes the number of test cases.
For each test case, the first line contains an integer . The next line contains non-negative integers .
Output Format
Output lines. For each test case, output one integer per line, which is the answer.
3
5
2 1 2 1 2
8
1000000000 1000000000 0 1000000000 1000000000 0 1000000000 1000000000
13
1 1 4 5 1 4 1 9 1 9 8 1 0
2
3000000000
19
Hint
Sample explanation .
Test case 1: $21212 \stackrel{1}{\longrightarrow} 1111 1 \stackrel{1}{\longrightarrow} 00000$.
Test case 3: $1145141919810 \stackrel{1}{\longrightarrow} 0034030808700 \stackrel{8}{\longrightarrow} 0031000000700 \stackrel{10}{\longrightarrow}0000000000000$.
Sample input and output are provided in the attached file.
Constraints:
For the first of the testdata, .
For the first of the testdata, .
For the first of the testdata, .
For the first of the testdata, .
For the first of the testdata, .
For the first of the testdata, .
For of the testdata, $1 \leq n \leq 100000, 0 \leq a_i \leq 10^9, 1 \leq T \leq 10$.
Translated by ChatGPT 5
京公网安备 11011102002149号