#SGM0000071. Truy vấn đoạn và bản sao (Range Queries and Copies)
Truy vấn đoạn và bản sao (Range Queries and Copies)
Range Queries and Copies
Source: CSES
Version: Phuoc Hung OJ Extended
Problem
Initially the list contains one array. Operation 1 k a x changes position of array to ; 2 k a b asks its range sum; 3 k appends an independent copy of array .
Input
The first line contains , followed by the initial array and operations.
Output
Print the answer to every type-2 operation.
Subtasks
Subtask 1 (20%)
- , number of queries .
- All other conditions are the same as Subtask 3.
Subtask 2 (30%)
- , number of queries .
- All other conditions are the same as Subtask 3.
Subtask 3 (50%)
- every version index refers to an existing array
Example
Input
5 6
2 3 1 2 5
3 1
2 1 1 5
2 2 1 5
1 2 2 5
2 1 1 5
2 2 1 5
Output
13
13
13
15
Explanation
After copying array 1, updating position 2 of array 2 changes only that copy. Their full sums become and .