#P5358. Array Operations and Queries
Array Operations and Queries
Array Operations and Queries
You are given an integer sequence of length n with elements numbered as \(a_1, a_2, a_3, \dots, a_n\). Initially, all elements are zero. Then, a series of operations (updates or queries) will be performed in chronological order. Each operation is one of the following six types:
- 1 i val: Assign the value val to \(a_i\);
- 2 val: Add the integer val to every element in the array;
- 3 val: Multiply every element in the array by the integer val;
- 4 val: Set every element in the array to the integer val;
- 5 i: Query the current value of \(a_i\);
- 6: Query the sum of all elements in the array.
Note that the operations will be provided one after the other, and the queries (operations of type 5 and 6) should output their results immediately in order.
All formulas are given in LaTeX format.
inputFormat
The first line contains two integers n and q, where n is the length of the array and q is the number of operations.
Each of the following q lines describes one operation in one of the six formats:
- For type 1:
1 i val
- For type 2:
2 val
- For type 3:
3 val
- For type 4:
4 val
- For type 5:
5 i
- For type 6:
6
outputFormat
For each query operation (type 5 or type 6), output the answer in a new line.
sample
5 5
1 3 10
2 5
5 3
3 2
6
15
70
</p>