#P2042. [NOI2005] 维护数列

[NOI2005] 维护数列

Description

Please write a program to maintain a sequence that supports the following 66 operations:

ID Name Format Note
1 Insert $\operatorname{INSERT}\ posi \ tot \ c_1 \ c_2 \cdots c_{tot}$ Insert tottot numbers c1,c2ctotc_1, c_2 \cdots c_{tot} after the posiposi-th number of the current sequence; if inserting at the beginning of the sequence, then posiposi is 00.
2 Delete DELETE posi tot\operatorname{DELETE} \ posi \ tot Starting from the posiposi-th number of the current sequence, delete tottot consecutive numbers.
3 Make-Same MAKE-SAME posi tot c\operatorname{MAKE-SAME} \ posi \ tot \ c Starting from the posiposi-th number of the current sequence, set tottot consecutive numbers all to cc.
4 Reverse REVERSE posi tot\operatorname{REVERSE} \ posi \ tot Take the tottot numbers starting from the posiposi-th number, reverse them, and put them back in the original position.
5 Get-Sum GET-SUM posi tot\operatorname{GET-SUM} \ posi \ tot Compute and output the sum of the tottot numbers starting from the posiposi-th number of the current sequence.
6 Max-Subarray Sum MAX-SUM\operatorname{MAX-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 NN and MM, where NN is the number of elements in the initial sequence, and MM is the number of operations to perform.

The second line contains NN numbers describing the initial sequence. Each of the following MM lines contains one command; see the table in the Description for the formats.

Output Format

For each GET-SUM\operatorname{GET-SUM} and MAX-SUM\operatorname{MAX-SUM} 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 11 number.
  • The input is guaranteed to be valid, i.e., the specified positions always exist in the sequence.
  • For 50%50\% of the testdata, the sequence contains at most 3×1043 \times 10^4 numbers at any time.
  • For 100%100\% of the testdata, the sequence contains at most 5×1055 \times 10^5 numbers at any time; each number is within [103,103][-10^3, 10^3] at any time; 1M2×1041 \le M \le 2 \times 10^4; the total count of inserted numbers does not exceed 4×1064 \times 10^6.

Problem statement provided by @syksykCCC.

Translated by ChatGPT 5