Codeforces Round 1026 (Div. 2)
C
Racing
Codeforces
1400
原题
← BD →
翻译中…

In 2077, a sport called hobby-droning is gaining popularity among robots.

翻译中…

You already have a drone, and you want to win. For this, your drone needs to fly through a course with $n$ obstacles.

翻译中…

The $i$-th obstacle is defined by two numbers $l_i, r_i$. Let the height of your drone at the $i$-th obstacle be $h_i$. Then the drone passes through this obstacle if $l_i \le h_i \le r_i$. Initially, the drone is on the ground, meaning $h_0 = 0$.

翻译中…

The flight program for the drone is represented by an array $d_1, d_2, \ldots, d_n$, where $h_{i} - h_{i-1} = d_i$, and $0 \leq d_i \leq 1$. This means that your drone either does not change height between obstacles or rises by $1$. You already have a flight program, but some $d_i$ in it are unknown and marked as $-1$. Replace the unknown $d_i$ with numbers $0$ and $1$ to create a flight program that passes through the entire obstacle course, or report that it is impossible.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

In the first line of each test case, an integer $n$ ($1 \le n \le 2 \cdot 10^5)$ is given — the size of the array $d$.

翻译中…

In the second line of each test case, there are $n$ integers $d_1, d_2, \ldots, d_n$ ($-1 \leq d_i \leq 1$) — the elements of the array $d$. $d_i = -1$ means that this $d_i$ is unknown to you.

翻译中…

Next, there are $n$ lines containing $2$ integers $l_i,r_i$ ($0\leq l_i\leq r_i\leq n$) — descriptions of the obstacles.

翻译中…

It is guaranteed that the sum of $n$ across all test cases does not exceed $2\cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, output $n$ integers $d_1,d_2,\ldots,d_n$, if it is possible to correctly restore the array $d$, or $-1$ if it is not possible.

翻译中…

Note

翻译中…

In the first test case, one possible answer is $d=[0,1,1,1]$. The array $h$ will be $[0,0+1,0+1+1,0+1+1+1]=[0,1,2,3]$. This array meets the conditions of the problem.

翻译中…

In the second test case, it can be proven that there is no suitable array $d$, so the answer is $-1$.

翻译中…

样例

Input #1
5
4
0 -1 -1 1
0 4
1 2
2 4
1 4
3
0 -1 -1
0 1
2 2
0 3
2
-1 -1
0 0
2 2
8
-1 -1 1 -1 -1 0 0 -1
0 0
0 1
0 2
0 2
1 3
0 4
2 5
4 5
1
0
1 1
Output #1
0 1 1 1
-1
-1
0 1 1 0 1 0 0 1
-1
InputCopy OutputCopy
题目信息
题号
2110C
时间限制
2 s
内存限制
256 MB
标签
构造
贪心

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