CF2162H.Beautiful Problem
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
For an array a of length n and three integers x, l, and r(1≤l≤r≤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 a of length n (1≤ai≤n), and m intervals [li,ri] (1≤li≤ri≤n).
For each x=1,2,…,n, answer the following question independently:
- Does there exist a rearrangement a′ of a, such that for all 1≤i≤m, f(a′,x,li,ri)=1?
对于长度为 n 的数组 a 和三个整数 x、l 与 r(满足 1≤l≤r≤n),定义:
f(a,x,l,r)={0,1,若若(x−minj=lr(aj))⋅(x−maxj=lr(aj))<0(x−minj=lr(aj))⋅(x−maxj=lr(aj))≥0
给定一个长度为 n 的数组 a(满足 1≤ai≤n)以及 m 个区间 [li,ri](满足 1≤li≤ri≤n)。
对每个 x=1,2,…,n,独立回答以下问题:
- 是否存在 a 的一个重排 a′,使得对所有 1≤i≤m,均有 f(a′,x,li,ri)=1?
输入格式
The first line contains a single integer t (1≤t≤2⋅104) — the number of test cases. Description of each testcase follows.
The first line contains two integers n and m (2≤n≤2000, 1≤m≤2000).
The next line contains n space-separated integers a1,a2,⋯,an (1≤ai≤n).
The next m lines each contain two space-separated integers li,ri (1≤li≤ri≤n), each denoting an interval.
It is guaranteed that the sum of n2 and the sum of m2 over all test cases does not exceed 4⋅106, respectively.
第一行包含一个整数 t(1≤t≤2⋅104),表示测试用例的数量。每个测试用例的描述如下:
第一行包含两个整数 n 和 m(2≤n≤2000,1≤m≤2000)。
第二行包含 n 个以空格分隔的整数 a1,a2,⋯,an(1≤ai≤n)。
接下来的 m 行,每行包含两个以空格分隔的整数 li,ri(1≤li≤ri≤n),分别表示一个区间。
保证所有测试用例中 n2 的总和与 m2 的总和均不超过 4⋅106。
输出格式
For each test case, output a binary string s. For x=1,2,…,n, sx=1 only if there exists a rearrangement a′ of a, such that for all 1≤i≤m, f(a′,x,li,ri)=1. Otherwise, sx=0.
对于每个测试用例,输出一个二进制字符串 s。对 x=1,2,…,n,当且仅当存在数组 a 的一个重排 a′,使得对所有 1≤i≤m 均满足 f(a′,x,li,ri)=1 时,sx=1;否则 sx=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=1, one valid rearrangement is a′=[1,1,3,4].
- For x=2, there is no rearrangement a′ of a satisfying f(a′,2,1,2)=f(a′,2,2,4)=1.
- For x=3, the only valid rearrangement is a′=[4,3,1,1].
- For x=4, one valid rearrangement is a′=[1,1,3,4].
在第一个测试用例中:
- 对于 x=1,一个合法的重排是 a′=[1,1,3,4]。
- 对于 x=2,不存在数组 a 的重排 a′ 满足 f(a′,2,1,2)=f(a′,2,2,4)=1。
- 对于 x=3,唯一合法的重排是 a′=[4,3,1,1]。
- 对于 x=4,一个合法的重排是 a′=[1,1,3,4]。
输入解题思路,AI测评打分。不知道怎么写?