#P8165. [eJOI 2021] AddK
[eJOI 2021] AddK
Problem Description
You are given an array containing integers and an integer . You need to perform operations of the following two types:
- : Replace the values of in order with the values of . Here are pairwise distinct.
- : Output the sum of elements over all consecutive subsequences of length within the interval .
Input Format
The first line contains two integers .
The second line contains integers, representing the integers of array .
The third line contains one integer , representing the number of operations.
The next lines each contain several integers, describing one operation.
Output Format
Output several lines of integers, which are the results of all type operations.
8 3
7 2 5 1 9 3 4 6
3
2 2 7 4
1 2 5 8
2 2 7 3
52
50
Hint
Sample Explanation
For the first query, you need to compute the sum of elements over all consecutive subsequences of length in . These subsequences are . Therefore the answer is .
For the second query, you need to replace in order with the values of . After the replacement, the array becomes .
For the third query, you need to compute the sum of elements over all consecutive subsequences of length in . These subsequences are . Therefore the answer is .
Constraints
This problem uses bundled testdata.
- Subtask 1 (36 pts): and .
- Subtask 2 (56 pts): and .
- Subtask 3 (8 pts): and .
For of the testdata, , , .
Notes
This problem is translated from eJOI2021 Day 1 A AddK.
Translated by ChatGPT 5