시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
20 초 (추가 시간 없음) | 1024 MB | 19 | 6 | 5 | 100.000% |
Carl has an array of N candies. The i-th element of the array (indexed starting from 1) is Ai representing sweetness value of the i-th candy. He would like to perform a series of Q operations. There are two types of operation:
The sweetness score of a subarray from index l to r is: Al × 1 - Al+1 × 2 + Al+2 × 3 - Al+3 × 4 + Al+4 × 5 ...
More formally, the sweetness score is the sum of (-1)i-lAi × (i - l + 1), for all i from l to r inclusive.
For example, the sweetness score of:
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, T. T test cases follow. Each test case begins with a line containing N and Q. The second line contains N integers describing the array. The i-th integer is Ai. The j-th of the following Q lines describe the j-th operation. Each line begins with a single character describing the type of operation (U
for update, Q
for query).
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:
Thus, the final output should be 9 + 2 - 19 = -8.
In sample case #2:
Thus, the final output should be -3.
Contest > Google > Kick Start > Google Kick Start 2020 > Round C D번