Maintaining a Sequence

삽입, 삭제, 구간 대입, 구간 뒤집기, 구간 합, 전체 최대 연속 부분합 질의를 지원하는 수열을 유지한다.

어려움9트리연결 리스트구현재귀아직 제출이 없습니다시간 제한2초메모리 제한256 MB

문제

Please write a program that maintains a sequence, supporting the following 6 operations:

OperationInput FormatDescription
1. InsertINSERT posi tot c1 c2 … ctotAfter the posi-th number in the current sequence, insert a total of tot numbers: c1c2, …, ctot. Insertion to the beginning of the sequence will have posi equal to 0.
2. DeleteDELETE posi totStarting at the posi-th number in the current sequence, delete a total of tot consecutive numbers.
3. ModifyMAKE-SAME posi tot cStarting at the posi-th number in the current sequence, change all the values of tot consecutive numbers to c.
4. ReverseREVERSE posi totStarting at the posi-th number in the current sequence, reverse the order of tot consecutive numbers.
5. Get SumGET-SUM posi totStarting at the posi-th number in the current sequence, output the sum of tot consecutive numbers.
6. Max SumMAX-SUMOutput the largest sum of any (non-empty) consecutive subsequence of the current sequence.

입력

The first line of input contains two integers N and M, where N is the initial length of the sequence and M is the number of operations.

The second line of input contains N integers, describing the initial sequence.

For the next M lines, each line will contain a command in one of the formats described above.

출력

For each GET-SUM or MAX-SUM operation in the input, output the result of the query on a separate line.

제한

  • You may assume that at any given time, the sequence will contain at least 1 number.
  • The data in the input is guaranteed to be valid, and will always refer to existing positions in the sequence.
  • The sequence may contain up to 500 000 numbers at any given moment.
  • The value of any number in the sequence will be in the range [-1000, 1000].
  • M ≤ 20 000
  • The sum of all inserted values will not exceed 4 000 000.
  • The input will not exceed 20MB.