#P2042. [NOI2005] 维护数列
[NOI2005] 维护数列
Description
Please write a program to maintain a sequence that supports the following operations:
| ID | Name | Format | Note |
|---|---|---|---|
| 1 | Insert | $\operatorname{INSERT}\ posi \ tot \ c_1 \ c_2 \cdots c_{tot}$ | Insert numbers after the -th number of the current sequence; if inserting at the beginning of the sequence, then is . |
| 2 | Delete | Starting from the -th number of the current sequence, delete consecutive numbers. | |
| 3 | Make-Same | Starting from the -th number of the current sequence, set consecutive numbers all to . | |
| 4 | Reverse | Take the numbers starting from the -th number, reverse them, and put them back in the original position. | |
| 5 | Get-Sum | Compute and output the sum of the numbers starting from the -th number of the current sequence. | |
| 6 | Max-Subarray Sum | Find a contiguous subarray of the current sequence with the maximum sum and output that maximum sum. |
Input Format
The first line contains two integers and , where is the number of elements in the initial sequence, and is the number of operations to perform.
The second line contains numbers describing the initial sequence. Each of the following lines contains one command; see the table in the Description for the formats.
Output Format
For each and operation in the input, print the result to the output in order, one answer (number) per line.
9 8
2 -6 3 5 1 -5 -3 6 3
GET-SUM 5 4
MAX-SUM
INSERT 8 3 -5 7 2
DELETE 12 1
MAKE-SAME 3 3 2
REVERSE 3 6
GET-SUM 5 4
MAX-SUM
-1
10
1
10
Hint
Constraints
- You may assume that at any time, the sequence contains at least number.
- The input is guaranteed to be valid, i.e., the specified positions always exist in the sequence.
- For of the testdata, the sequence contains at most numbers at any time.
- For of the testdata, the sequence contains at most numbers at any time; each number is within at any time; ; the total count of inserted numbers does not exceed .
Problem statement provided by @syksykCCC.
Translated by ChatGPT 5
京公网安备 11011102002149号