#P16758. [GKS 2020 #C] Candies

[GKS 2020 #C] Candies

Problem Description

Carl has an array of NN candies. The i-th element of the array (indexed starting from 1) is AiA_i, representing sweetness value of the i-th candy. He would like to perform a series of QQ operations. There are two types of operation:

  • Update the sweetness value of a candy in the array.
  • Query the sweetness score of a subarray.

The sweetness score of a subarray from index ll to rr is: $A_l \times 1 - A_{l+1} \times 2 + A_{l+2} \times 3 - A_{l+3} \times 4 + A_{l+4} \times 5 ...$

More formally, the sweetness score is the sum of (1)ilAi×(il+1)(-1)^{i-l} A_i \times (i - l + 1), for all ii from ll to rr inclusive.

For example, the sweetness score of:

  • [3,1,6][3, 1, 6] is 3×11×2+6×3=193 \times 1 - 1 \times 2 + 6 \times 3 = 19
  • [40,30,20,10][40, 30, 20, 10] is $40 \times 1 - 30 \times 2 + 20 \times 3 - 10 \times 4 = 0$
  • [2,100][2, 100] is 2×1100×2=1982 \times 1 - 100 \times 2 = -198

Carl is interested in finding out the total sum of sweetness scores of all queries. If there is no query operation, the sum is considered to be 0. Can you help Carl find the sum?

Input Format

The first line of the input gives the number of test cases, TT. TT test cases follow. Each test case begins with a line containing NN and QQ. The second line contains NN integers describing the array. The i-th integer is AiA_i. The j-th of the following QQ lines describe the j-th operation. Each line begins with a single character describing the type of operation (UU for update, QQ for query).

  • For an update operation, two integers XjX_j and VjV_j follow, indicating that the XjX_j-th element of the array is changed to VjV_j.
  • For a query operation, two integers LjL_j and RjR_j follow, querying the sweetness score of the subarray from the LjL_j-th element to the RjR_j-th element (inclusive).

Output Format

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the total sum of sweetness scores of all the queries.

2
5 4
1 3 9 8 2
Q 2 4
Q 5 5
U 2 10
Q 1 2
3 3
4 5 5
U 1 2
U 1 7
Q 1 2
Case #1: -8
Case #2: -3

Hint

In sample case #1:

  • The first query asks for the sweetness score of [3,9,83, 9, 8] which is 3×19×2+8×3=93 \times 1 - 9 \times 2 + 8 \times 3 = 9.
  • The second query asks for the sweetness score of [22] which is 2×1=22 \times 1 = 2.
  • The third query asks for the sweetness score of [1,101, 10] which is 1×110×2=191 \times 1 - 10 \times 2 = -19.

Thus, the final output should be 9+219=89 + 2 - 19 = -8.

In sample case #2:

  • The first and only query asks for the sweetness score of [7,57, 5] which is 7×15×2=37 \times 1 - 5 \times 2 = -3.

Thus, the final output should be -3.

Limits

1T1001 \le T \le 100.

1Ai1001 \le A_i \le 100, for all ii.

1N2×1051 \le N \le 2 \times 10^5 and 1Q1051 \le Q \le 10^5 for at most 66 test cases.

For the remaining cases, 1N3001 \le N \le 300 and 1Q3001 \le Q \le 300.

If the j-th operation is an update operation, 1XjN1 \le X_j \le N and 1Vj1001 \le V_j \le 100.

If the j-th operation is a query operation, 1LjRjN1 \le L_j \le R_j \le N.

Test Set 1

There will be at most 55 update operations.

Test Set 2

There are no special constraints.