#P8862. 「KDOI-03」还原数据

    ID: 9886 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>线段树2022洛谷原创Special JudgeO2优化构造

「KDOI-03」还原数据

Problem Description

Little E is working on a classic problem:

Given a sequence aa of length nn and qq operations, there are 22 types of operations:

  • 1 l r x\tt{1~l~r~x}: For all lirl \le i \le r, set aiai+xa_i \leftarrow a_i + x.
  • 2 l r x\tt{2~l~r~x}: For all lirl \le i \le r, set aimax(ai,x)a_i \leftarrow \max(a_i, x).

The task is to output the final sequence aa' after all operations are finished.

Little E quickly wrote some code and submitted it, but then found that, due to cosmic rays, the input data had some minor issues. Specifically, for all type 22 operations, the given xx was lost. That is, in the input data, every type 22 operation only remains as 2 l r\tt{2~l~r}. The output data has no problem. Little E now wants to restore the original input data from the remaining data. Please help him complete this task.

Of course, there may be multiple valid original inputs. You only need to find any one of them. The testdata guarantees that a solution exists.

Input Format

Read from standard input.

This problem has multiple test cases.

The first line contains a positive integer TT, the number of test cases.

For each test case, the first line contains two non-negative integers n,qn, q.

The second line contains nn integers, the initial sequence a1,a2,,ana_1, a_2, \ldots, a_n.

The next qq lines each contain one operation, in the form 1 l r x\tt{1~l~r~x} or 2 l r\tt{2~l~r}.

The next line contains nn integers, the final sequence a1,a2,,ana_1', a_2', \ldots, a_n'.

Output Format

Output to standard output.

This problem uses a Special Judge.

For each test case, suppose there are q2q_2 type 22 operations in total. Output one line with q2q_2 integers. The ii-th integer represents the value of xx given in the ii-th type 22 operation.

You must ensure that 1015x1015-10^{15} \le x \le 10^{15}.

1
5 3
1 2 3 4 5
2 3 5
1 3 4 2
2 1 1
20 2 5 6 5

3 20

Hint

[Sample 1 Explanation]

All valid outputs must satisfy: the 11-st number 3\le 3, and the 22-nd number is exactly 2020.

[Sample 2]

See restore/restore2.in and restore/restore2.ans in the contestant files.

[Sample 3]

See restore/restore3.in and restore/restore3.ans in the contestant files.


[Constraints]

Let q2q_2 be the number of type 22 operations in one test case. Let n\sum n be the sum of all nn within one test point, and q\sum q be the sum of all qq within one test point.

For 20%20\% of the testdata, n,q50n, q \le 50, and n,q1 000\sum n, \sum q \le 1~000.

For 40%40\% of the testdata, n,q1 000n, q \le 1~000, and n,q105\sum n, \sum q \le 10^5.

For another 20%20\% of the testdata, l=1,r=nl = 1, r = n.

For another 20%20\% of the testdata, q2100q_2 \le 100.

For 100%100\% of the testdata, 1T1001 \le T \le 100, 1n,q1051 \le n, q \le 10^5, 1n,q3×1051 \le \sum n, \sum q \le 3 \times 10^5, 109ai,x109-10^9 \le a_i, x \le 10^9, 1015ai1015-10^{15} \le a_i' \le 10^{15}, and q21q_2 \ge 1.


[Checker]

The sample files for this problem are large and cannot be downloaded as attachments. Please view them in the contestant files.

To make testing easier, we provide a checker.cpp file in the restore\texttt{restore} directory. You can compile it and use it to check your output file. Note that it is not exactly the same as the checker used in the final judging, and you do not need to and should not care about the specific code details.

The compile command is:

g++ checker.cpp -o checker -std=c++14

Usage:

./checker <inputfile> <outputfile> <answerfile>

The checker may return one of the following statuses:

  • Accepted\tt{Accepted}: Your output is completely correct.
  • Wrong answer at testcase x\tt{Wrong~answer~at~testcase~ x}: Your output is wrong on test case xx.

[Hint]

The input and output size of this problem is large, so faster I/O methods are recommended.

A warm reminder from the KDOI problem setters: if you do not clear arrays between test cases, you may get zero points and cry for two lines.

Translated by ChatGPT 5