Refact.ai Match 1 (Codeforces Round 985)
G
Balanced Problem
Codeforces
3000
原题
← FH →
翻译中…

There is an array $a$ consisting of $n$ integers. Initially, all elements of $a$ are equal to $0$.

翻译中…

Kevin can perform several operations on the array. Each operation is one of the following two types:

翻译中…
  • Prefix addition — Kevin first selects an index $x$ ($1\le x\le n$), and then for each $1\le j\le x$, increases $a_j$ by $1$;
  • Suffix addition — Kevin first selects an index $x$ ($1\le x\le n$), and then for each $x\le j\le n$, increases $a_j$ by $1$.
翻译中…

In the country of KDOI, people think that the integer $v$ is balanced. Thus, Iris gives Kevin an array $c$ consisting of $n$ integers and defines the beauty of the array $a$ as follows:

翻译中…
  • Initially, set $b=0$;
  • For each $1\le i\le n$, if $a_i=v$, add $c_i$ to $b$;
  • The beauty of $a$ is the final value of $b$.
翻译中…

Kevin wants to maximize the beauty of $a$ after all the operations. However, he had already performed $m$ operations when he was sleepy. Now, he can perform an arbitrary number (possibly zero) of new operations.

翻译中…

You have to help Kevin find the maximum possible beauty if he optimally performs the new operations.

翻译中…

However, to make sure that you are not just rolling the dice, Kevin gives you an integer $V$, and you need to solve the problem for each $1\le v\le V$.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line of the input contains a single integer $t$ ($1\le t\le 1000$) — the number of test cases. The description of test cases follows.

翻译中…

The first line of each test case contains three integers $n$, $m$, and $V$ ($1\le n, m\le 2\cdot 10^5$, $1\le V\le 2000$) — the length of the array $a$, the number of initial operations, and the number that Kevin gives you.

翻译中…

The second line contains $n$ integers $c_1, c_2, \ldots, c_n$ ($1\le c_i\le 10^9$) — the elements in the array $c$.

翻译中…

Then $m$ lines follow, the $i$-th line containing a character $op$ and an integer $x$ ($op=\mathtt{L}$ or $\mathtt{R}$, $1\le x\le n$) — the type of the $i$-th operation and the selected index.

翻译中…
  • If $op=\mathtt{L}$, this operation is a prefix addition on index $x$;
  • If $op=\mathtt{R}$, this operation is a suffix addition on index $x$.
翻译中…

It is guaranteed that:

翻译中…
  • the sum of $n$ over all test cases does not exceed $2\cdot 10^5$;
  • the sum of $m$ over all test cases does not exceed $2\cdot 10^5$;
  • the sum of $V^2$ over all test cases does not exceed $4\cdot 10^6$.
翻译中…

Output

翻译中…

For each test case, output $V$ integers in a single line, the $i$-th integer denoting the maximum possible beauty after Kevin performs some new operations when $v=i$.

翻译中…

Note

翻译中…

In the first test case, the array $a$ changes as follows for the initial operations: $[0, 0, 0] \xrightarrow{\mathtt{L}\ 3} [1, 1, 1] \xrightarrow{\mathtt{R}\ 3} [1, 1, 2] \xrightarrow{\mathtt{L}\ 1} [2, 1, 2]$.

翻译中…
  • For $v=1$, it is optimal to not perform any new operations, and the beauty is $b=c_2=2$;
  • For $v=2$, it is optimal to perform a prefix addition operation on index $2$. After that, $a$ becomes $[3,2,2]$, and the beauty is $b=c_2+c_3=6$.
翻译中…

In the second test case, for both $v=1$ and $v=2$, it is optimal to not perform any new operations.

翻译中…

样例

Input #1
5
3 3 2
1 2 4
L 3
R 3
L 1
3 3 2
5 1 4
L 3
R 3
L 1
5 4 5
1 1 1 1 1
L 3
R 2
L 5
L 4
10 12 9
10 9 8 7 6 5 4 3 2 1
L 2
L 4
R 4
R 4
L 6
R 8
L 3
L 2
R 1
R 10
L 8
L 1
1 1 4
1000000000
L 1
Output #1
2 6
1 9
0 1 3 5 5
0 0 0 6 25 32 35 44 51
1000000000 1000000000 1000000000 1000000000
InputCopy OutputCopy
题目信息
题号
2029G
时间限制
3 s
内存限制
1024 MB
标签
数据结构
动态规划

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。