#P1887C. Minimum Array

    ID: 8796 Type: RemoteJudge 3000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>binary searchbrute forceconstructive algorithmsdata structuresgreedyhashingtwo pointers

Minimum Array

No submission language available for this problem.

Description

Given an array aa of length nn consisting of integers. Then the following operation is sequentially applied to it qq times:

  • Choose indices ll and rr (1lrn1 \le l \le r \le n) and an integer xx;
  • Add xx to all elements of the array aa in the segment [l,r][l, r]. More formally, assign ai:=ai+xa_i := a_i + x for all lirl \le i \le r.

Let bjb_j be the array aa obtained after applying the first jj operations (0jq0 \le j \le q). Note that b0b_0 is the array aa before applying any operations.

You need to find the lexicographically minimum^{\dagger} array among all arrays bjb_j.

^{\dagger}An array xx is lexicographically smaller than array yy if there is an index ii such that xi<yix_i < y_i, and xj=yjx_j = y_j for all j<ij < i. In other words, for the first index ii where the arrays differ, xi<yix_i < y_i.

Each test consists of multiple test cases. The first line contains a single integer tt (1t51051 \le t \le 5 \cdot 10^5) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (1n51051 \le n \le 5 \cdot 10^5) — the length of array aa.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (109ai109-10^9 \le a_i \le 10^9) — the elements of array aa.

The third line of each test case contains a single integer qq (0q51050 \le q \le 5 \cdot 10^5) — the number of operations on the array.

In each of the next qq lines, there are three integers ljl_j, rjr_j, and xjx_j (1ljrjn,109xj109)(1 \le l_j \le r_j \le n, -10^9 \le x_j \le 10^9) — the description of each operation. The operations are given in the order they are applied.

It is guaranteed that the sum of nn over all test cases and the sum of qq over all test cases do not exceed 51055 \cdot 10^5.

For each test case, output the lexicographically minimum array among all arrays bjb_j.

Input

Each test consists of multiple test cases. The first line contains a single integer tt (1t51051 \le t \le 5 \cdot 10^5) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (1n51051 \le n \le 5 \cdot 10^5) — the length of array aa.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (109ai109-10^9 \le a_i \le 10^9) — the elements of array aa.

The third line of each test case contains a single integer qq (0q51050 \le q \le 5 \cdot 10^5) — the number of operations on the array.

In each of the next qq lines, there are three integers ljl_j, rjr_j, and xjx_j (1ljrjn,109xj109)(1 \le l_j \le r_j \le n, -10^9 \le x_j \le 10^9) — the description of each operation. The operations are given in the order they are applied.

It is guaranteed that the sum of nn over all test cases and the sum of qq over all test cases do not exceed 51055 \cdot 10^5.

Output

For each test case, output the lexicographically minimum array among all arrays bjb_j.

Sample Input 1

2
4
1 2 3 4
2
1 4 0
1 3 -100
5
2 1 2 5 4
3
2 4 3
2 5 -2
1 3 1

Sample Output 1

-99 -98 -97 4 
2 1 2 5 4

Note

In the first test case:

  • b0=[1,2,3,4]b_0 = [1,2,3,4];
  • b1=[1,2,3,4]b_1 = [1,2,3,4];
  • b2=[99,98,97,4]b_2 = [-99,-98,-97,4].

Thus, the lexicographically minimum array is b2b_2.

In the second test case, the lexicographically minimum array is b0b_0.