Codeforces Round 905 (Div. 1)
C
Minimum Array
Codeforces
2400
原题
← BD →
翻译中…

Given an array $a$ of length $n$ consisting of integers. Then the following operation is sequentially applied to it $q$ times:

翻译中…
  • Choose indices $l$ and $r$ ($1 \le l \le r \le n$) and an integer $x$;
  • Add $x$ to all elements of the array $a$ in the segment $[l, r]$. More formally, assign $a_i := a_i + x$ for all $l \le i \le r$.
翻译中…

Let $b_j$ be the array $a$ obtained after applying the first $j$ operations ($0 \le j \le q$). Note that $b_0$ is the array $a$ before applying any operations.

翻译中…

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

翻译中…

$^{\dagger}$An array $x$ is lexicographically smaller than array $y$ if there is an index $i$ such that $x_i \lt y_i$, and $x_j = y_j$ for all $j \lt i$. In other words, for the first index $i$ where the arrays differ, $x_i \lt y_i$.

翻译中…

Input

翻译中…

Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \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 $n$ ($1 \le n \le 5 \cdot 10^5$) — the length of array $a$.

翻译中…

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$) — the elements of array $a$.

翻译中…

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

翻译中…

In each of the next $q$ lines, there are three integers $l_j$, $r_j$, and $x_j$ $(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 $n$ over all test cases and the sum of $q$ over all test cases do not exceed $5 \cdot 10^5$.

翻译中…

Output

翻译中…

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

翻译中…

Note

翻译中…

In the first test case:

翻译中…
  • $b_0 = [1,2,3,4]$;
  • $b_1 = [1,2,3,4]$;
  • $b_2 = [-99,-98,-97,4]$.
翻译中…

Thus, the lexicographically minimum array is $b_2$.

翻译中…

In the second test case, the lexicographically minimum array is $b_0$.

翻译中…

样例

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
Output #1
-99 -98 -97 4
2 1 2 5 4
InputCopy OutputCopy
题目信息
题号
1887C
时间限制
3 s
内存限制
256 MB
标签
二分
暴力
构造
数据结构
贪心
哈希
双指针

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