CF2162H.Beautiful Problem

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

For an array aa of length nn and three integers xx, ll, and rr(1≤l≤r≤n1 \le l \le r \le n), define:

f(a,x,l,r) = \\begin{cases} 0, & \\text{if} & (x-\\min\_{j=l}^{r}(a\_j)) \\cdot (x-\\max\_{j=l}^{r}(a\_j))) \\lt 0 \\\\ 1, & \\text{if} & (x-\\min\_{j=l}^{r}(a\_j)) \\cdot (x-\\max\_{j=l}^{r}(a\_j))) \\ge 0 \\end{cases}

You are given an array aa of length nn (1≤ai≤n1 \le a_i \le n), and mm intervals [li,ri][l_i, r_i] (1≤li≤ri≤n1 \le l_i \le r_i \le n).

For each x=1,2,…,nx=1, 2, \dots, n, answer the following question independently:

  • Does there exist a rearrangement a′a' of aa, such that for all 1≤i≤m1 \le i \le m, f(a′,x,li,ri)=1f(a',x,l_i,r_i) = 1?

对于长度为 nn 的数组 aa 和三个整数 xx、ll 与 rr(满足 1≤l≤r≤n1 \le l \le r \le n),定义:

f(a,x,l,r)={0,若(x−min⁡j=lr(aj))⋅(x−max⁡j=lr(aj))<01,若(x−min⁡j=lr(aj))⋅(x−max⁡j=lr(aj))≥0f(a,x,l,r) = \begin{cases} 0, & \text{若} & (x-\min_{j=l}^{r}(a_j)) \cdot (x-\max_{j=l}^{r}(a_j)) < 0 \\ 1, & \text{若} & (x-\min_{j=l}^{r}(a_j)) \cdot (x-\max_{j=l}^{r}(a_j)) \ge 0 \end{cases}

给定一个长度为 nn 的数组 aa(满足 1≤ai≤n1 \le a_i \le n)以及 mm 个区间 [li,ri][l_i, r_i](满足 1≤li≤ri≤n1 \le l_i \le r_i \le n)。

对每个 x=1,2,…,nx = 1, 2, \dots, n,独立回答以下问题:

  • 是否存在 aa 的一个重排 a′a',使得对所有 1≤i≤m1 \le i \le m,均有 f(a′,x,li,ri)=1f(a',x,l_i,r_i) = 1?

输入格式

The first line contains a single integer tt (1≤t≤2⋅1041 \le t \le 2 \cdot 10^4) — the number of test cases. Description of each testcase follows.

The first line contains two integers nn and mm (2≤n≤20002 \le n \le 2000, 1≤m≤20001 \le m \le 2000).

The next line contains nn space-separated integers a1,a2,⋯ ,ana_1, a_2, \cdots, a_n (1≤ai≤n1 \le a_i \le n).

The next mm lines each contain two space-separated integers li,ril_i, r_i (1≤li≤ri≤n1 \le l_i \le r_i \le n), each denoting an interval.

It is guaranteed that the sum of n2n^2 and the sum of m2m^2 over all test cases does not exceed 4⋅1064 \cdot 10^6, respectively.

第一行包含一个整数 tt(1≤t≤2⋅1041 \le t \le 2 \cdot 10^4),表示测试用例的数量。每个测试用例的描述如下:

第一行包含两个整数 nn 和 mm(2≤n≤20002 \le n \le 2000,1≤m≤20001 \le m \le 2000)。

第二行包含 nn 个以空格分隔的整数 a1,a2,⋯ ,ana_1, a_2, \cdots, a_n(1≤ai≤n1 \le a_i \le n)。

接下来的 mm 行,每行包含两个以空格分隔的整数 li,ril_i, r_i(1≤li≤ri≤n1 \le l_i \le r_i \le n),分别表示一个区间。

保证所有测试用例中 n2n^2 的总和与 m2m^2 的总和均不超过 4⋅1064 \cdot 10^6。

输出格式

For each test case, output a binary string ss. For x=1,2,…,nx=1,2,\ldots,n, sx=1s_x=1 only if there exists a rearrangement a′a' of aa, such that for all 1≤i≤m1 \le i \le m, f(a′,x,li,ri)=1f(a',x,l_i,r_i) = 1. Otherwise, sx=0s_x=0.

对于每个测试用例,输出一个二进制字符串 ss。对 x=1,2,…,nx=1,2,\ldots,n,当且仅当存在数组 aa 的一个重排 a′a',使得对所有 1≤i≤m1 \le i \le m 均满足 f(a′,x,li,ri)=1f(a',x,l_i,r_i) = 1 时,sx=1s_x=1;否则 sx=0s_x=0。

输入输出样例

  • 输入#1

    4
    4 2
    1 1 3 4
    1 2
    2 4
    3 2
    1 1 3
    1 2
    2 3
    3 1
    1 1 1
    1 3
    9 3
    4 5 9 1 1 1 2 2 3
    1 6
    3 7
    7 9

    输出#1

    1011
    101
    111
    100100001

说明/提示

In the first test case,

  • For x=1x=1, one valid rearrangement is a′=[1,1,3,4]a'=[1,1,3,4].
  • For x=2x=2, there is no rearrangement a′a' of aa satisfying f(a′,2,1,2)=f(a′,2,2,4)=1f(a',2,1,2)=f(a',2,2,4)=1.
  • For x=3x=3, the only valid rearrangement is a′=[4,3,1,1]a'=[4,3,1,1].
  • For x=4x=4, one valid rearrangement is a′=[1,1,3,4]a'=[1,1,3,4].

在第一个测试用例中:

  • 对于 x=1x=1,一个合法的重排是 a′=[1,1,3,4]a'=[1,1,3,4]。
  • 对于 x=2x=2,不存在数组 aa 的重排 a′a' 满足 f(a′,2,1,2)=f(a′,2,2,4)=1f(a',2,1,2)=f(a',2,2,4)=1。
  • 对于 x=3x=3,唯一合法的重排是 a′=[4,3,1,1]a'=[4,3,1,1]。
  • 对于 x=4x=4,一个合法的重排是 a′=[1,1,3,4]a'=[1,1,3,4]。

输入解题思路,AI测评打分。不知道怎么写?

首页