#P16758. [GKS 2020 #C] Candies

    ID: 17019 Type: RemoteJudge 2000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 6 Uploaded By: Tags>2020线段树树状数组分块Google Kick Start

[GKS 2020 #C] Candies

题目描述

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)i−lAi×(i−l+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×1−1×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×1−100×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?

输入格式

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).

输出格式

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

提示

In sample case #1:

  • The first query asks for the sweetness score of [3,9,83, 9, 8] which is 3×1−9×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×1−10×2=−191 \times 1 - 10 \times 2 = -19.

Thus, the final output should be 9+2−19=−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×1−5×2=−37 \times 1 - 5 \times 2 = -3.

Thus, the final output should be -3.

Limits

1≤T≤1001 \le T \le 100.

1≤Ai≤1001 \le A_i \le 100, for all ii.

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

For the remaining cases, 1≤N≤3001 \le N \le 300 and 1≤Q≤3001 \le Q \le 300.

If the j-th operation is an update operation, 1≤Xj≤N1 \le X_j \le N and 1≤Vj≤1001 \le V_j \le 100.

If the j-th operation is a query operation, 1≤Lj≤Rj≤N1 \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.