Dynamic Sequence Data Structure
Time limit1sMemory limit128 MB
Design a data structure supporting range assignment, range arithmetic-progression addition, mid-sequence insertion, and range-sum queries efficiently.
- Level
Hard8 of 10
- Topics
- Segment tree, Array, Implementation
- Solved
- No attempts yet
Problem
You are given an integer sequence and must process the following four operations in order. Positions are 1-indexed in the current sequence.
Given the initial sequence and the list of operations, write a program that prints the result whenever an operation of type 4 appears.
Input
The first line contains N and Q. N is the size of the initial sequence, and Q is the number of operations. (1 <= N, Q <= 100,000)
The second line contains the N elements of the initial sequence, separated by spaces. Each element is a nonnegative integer not greater than 100,000.
The next Q lines contain the operations in order. For operations that contain X, 0 <= X <= 100. For range operations, 1 <= A <= B <= the current sequence size. For insertion operations, 1 <= C <= the current sequence size+1.
Output
For each operation of type 4, print the corresponding range sum on its own line. The sum can exceed the range of a 32-bit integer.