#P8454. 「SWTR-8」补题计划

    ID: 7515 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>线段树洛谷原创O2优化洛谷月赛

「SWTR-8」补题计划

Description

Little A has a total of nn problems that he has not made up. After evaluation, he thinks the difficulty of problem ii is xix_i.

At the same time, he has an evaluation value ww for his own level. His level may fluctuate, so ww will change.

Little A believes that making up problems whose difficulty is close to his level (difference no more than b1b_1) brings a benefit incinc; on the contrary, if the difference is too large (difference greater than b2b_2), it wastes time and causes a negative benefit decdec. Therefore, the benefit of making up problem ii is

$$\begin{cases} inc & |x_i - w| \leq b_1 \\ 0 & b_1 < |x_i - w| \leq b_2 \\ dec & |x_i - w| > b_2 \\ \end{cases}$$

It is guaranteed that b1b2b_1 \leq b_2 and dec<0<incdec < 0 < inc.

In addition, Little A has some problems he likes and dislikes. If he does not make up any liked problem, or if he makes up any disliked problem, he will be unhappy.

Little A will choose a consecutive segment of problems (by index) to make up. He wants to maximize the sum of benefits of all chosen problems, and he must not be unhappy after finishing. Please tell him this maximum value.

All queries are independent of each other.

Input Format

The first line contains an integer SS, indicating the Subtask number of this test point.

The second line contains seven integers n,q,w,b1,b2,inc,decn, q, w, b_1, b_2, inc, dec, where qq is the number of events.

The third line contains nn integers x1,x2,,xnx_1, x_2, \cdots, x_n.

The following lines describe events. Each event takes either one line or three lines:

  • First an integer op{1,2}op\in \{1, 2\}.
  • If op=1op = 1, then the next two integers l,hl, h represent the number of liked problems and disliked problems; the next line contains ll integers il1,il2,,illil_1, il_2, \cdots, il_l, the indices of liked problems; the next line contains hh integers ih1,ih2,,ihhih_1, ih_2, \cdots, ih_h, the indices of disliked problems. It is guaranteed that any iliihjil_i \neq ih_j.
  • If op=2op = 2, then the next integer ww is the new level evaluation value.

Output Format

For each event with op=1op = 1, output one line with one integer, the answer.

0
7 7 1 2 3 2 -3
1 0 6 4 8 2 2
1 1 1
4
3
1 2 0
3 4

1 2 0
2 4

2 1064
1 1 0
1

2 5
1 2 2
2 7
4 6
1
2
4
-3
0

Hint

"Sample Explanation"

When w=1w = 1, the benefits of each problem are 2,2,3,0,3,2,22, 2, -3, 0, -3, 2, 2.

In the first query, you must make up problem 44, and you must not make up problem 33. The optimal choice is [4,7][4, 7], with benefit 11.

In the second query, you must make up problem 33 or problem 44. The optimal choice is [1,7][1, 7], with benefit 22.

In the third query, you must make up problem 22 or problem 44. The optimal choice is [1,2][1, 2], with benefit 44.

When w=1064w = 1064, the benefit of every problem is 3-3.

In the fourth query, you must make up problem 11. The optimal choice is [1,1][1, 1], with benefit 3-3.

When w=5w = 5, the benefits of each problem are 3,3,2,2,0,0,0-3, -3, 2, 2, 0, 0, 0.

In the fifth query, you must make up problem 22 or problem 77, and you must not make up problems 44 and 66. The optimal choice is [7,7][7, 7], with benefit 00.

"Constraints and Notes"

This problem uses bundled tests.

  • Subtask #1 (7 points): n,q100n, q\leq 100.
  • Subtask #2 (12 points): n,q500n, q\leq 500. Depends on Subtask #1.
  • Subtask #3 (20 points): n,q4×103n, q\leq 4 \times 10 ^ 3. Depends on Subtask #2.
  • Subtask #4 (25 points): w,xi100w, x_i \leq 100.
  • Subtask #5 (11 points): l=1l = 1, h=0h = 0.
  • Subtask #6 (15 points): w,xi105w, x_i \leq 10 ^ 5. Depends on Subtask #4.
  • Subtask #7 (10 points): no special constraints. Depends on Subtask #3, #5, #6.

For 100%100\% of the data:

  • 1n,q1051\leq n, q \leq 10 ^ 5.
  • 0w,xi1090\leq w, x_i \leq 10 ^ 9, 0b1b20\leq b_1 \leq b_2, and b2b_2 is no more than half of the upper bound of w,xiw, x_i.
  • 104dec<0<inc104-10 ^ 4 \leq dec < 0 < inc \leq 10 ^ 4.
  • 1l,ili,ihjn1\leq l, il_i, ih_j \leq n, 0h<n0 \leq h < n, l+h5l + h\leq 5.
  • It is guaranteed that ilil and ihih are increasing, and within one query each index appears at most once.

"Help and Tips"

Please pay attention to I/O optimization.

"Problem Source"

Translated by ChatGPT 5