CF1893D.Colorful Constructive

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

You have nn colored cubes, the ii-th cube has color aia_i.

You need to distribute all the cubes on shelves. There are a total of mm shelves, the ii-th shelf can hold sis_i cubes. Also, s1+s2+…+sm=ns_1 + s_2 + \ldots + s_m = n.

Suppose on a shelf of size kk there are cubes of colors c1,c2,…,ckc_1, c_2, \ldots, c_k, in this order. Then we define the colorfulness of the shelf as the minimum distance between two different cubes of the same color on the shelf. If all the cubes on the shelf have different colors, then the colorfulness is considered to be equal to the size of the shelf, that is, the number kk.

More formally, the colorfulness of c1,c2,…,ckc_1, c_2, \ldots, c_k is defined as follows:

  • If all the colors c1,c2,…,ckc_1, c_2, \ldots, c_k are different, the colorfulness is considered to be kk.
  • Otherwise, the colorfulness is considered to be the smallest integer x≥1x \geq 1 such that there exists an index ii (1≤i≤k−x)(1 \le i \le k - x) such that ci=ci+xc_i = c_{i+x}.

For each shelf, you are given the minimum required colorfulness, that is, you are given numbers d1,d2,…,dmd_1, d_2, \ldots, d_m, which mean that shelf ii must have a colorfulness ≥di\geq d_i for all ii.

Distribute the available cubes among the shelves to ensure the required colorfulness, or report that it is impossible.

你有 nn 个彩色立方体,其中第 ii 个立方体的颜色为 aia_i。

你需要将所有立方体分配到书架上。一共有 mm 个书架,其中第 ii 个书架最多可容纳 sis_i 个立方体。此外,满足 s1+s2+…+sm=ns_1 + s_2 + \ldots + s_m = n。

假设一个容量为 kk 的书架上按顺序摆放着颜色为 c1,c2,…,ckc_1, c_2, \ldots, c_k 的立方体,则该书架的“色彩丰富度”(colorfulness)定义为:该书架上任意两个颜色相同但位置不同的立方体之间的最小距离。若该书架上所有立方体颜色互不相同,则其色彩丰富度定义为该书架的容量,即整数 kk。

更形式化地,序列 c1,c2,…,ckc_1, c_2, \ldots, c_k 的色彩丰富度定义如下:

  • 若所有颜色 c1,c2,…,ckc_1, c_2, \ldots, c_k 互不相同,则色彩丰富度为 kk;
  • 否则,色彩丰富度为满足如下条件的最小整数 x≥1x \geq 1:存在下标 ii(满足 1≤i≤k−x1 \le i \le k - x),使得 ci=ci+xc_i = c_{i+x}。

对每个书架,题目给出其所需的最小色彩丰富度,即给定整数 d1,d2,…,dmd_1, d_2, \ldots, d_m,表示第 ii 个书架的色彩丰富度必须满足 ≥di\geq d_i(对所有 ii)。

请将给定的立方体分配到各书架上,使其满足所有 did_i 的约束;若无法实现,请报告无解。

输入格式

Each test contains multiple test cases. The first line contains a single integer tt (1≤t≤104)(1 \leq t \leq 10^4) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers n,mn, m (1≤m≤n≤2⋅105)(1 \leq m \leq n \leq 2 \cdot 10^5) — the number of cubes and the number of shelves to distribute them to.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤n)(1 \leq a_i \leq n) — the colors of the cubes.

The third line of each test case contains mm integers s1,s2,…,sms_1, s_2, \ldots, s_m (1≤si≤n)(1 \leq s_i \leq n) — the sizes of the shelves. It's guaranteed, that s1+…+sm=ns_1 + \ldots + s_m = n.

The fourth line of each test case contains mm integers d1,d2,…,dmd_1, d_2, \ldots, d_m (1≤di≤si)(1 \leq d_i \leq s_i) — the minimum required colorfulness of the shelves.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 n,mn, m(1≤m≤n≤2⋅1051 \leq m \leq n \leq 2 \cdot 10^5),分别表示立方体的数量以及用于放置这些立方体的架子数量。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤n1 \leq a_i \leq n),表示各立方体的颜色。

每个测试用例的第三行包含 mm 个整数 s1,s2,…,sms_1, s_2, \ldots, s_m(1≤si≤n1 \leq s_i \leq n),表示各架子的容量。保证 s1+…+sm=ns_1 + \ldots + s_m = n。

每个测试用例的第四行包含 mm 个整数 d1,d2,…,dmd_1, d_2, \ldots, d_m(1≤di≤si1 \leq d_i \leq s_i),表示各架子所需的最小“色彩丰富度”。

保证所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, if it is impossible to distribute the cubes on the shelves satisfying all the requirements, output a single number −1-1. Otherwise, output mm lines, where the ii-th line should contain sis_i numbers representing the colors of the cubes on the ii-th shelf, in the appropriate order.

对于每个测试用例,如果无法在满足所有要求的前提下将立方体分配到书架上,则输出单个数字 −1-1。否则,输出 mm 行,其中第 ii 行应包含 sis_i 个数字,表示第 ii 个书架上立方体的颜色(按适当顺序排列)。

输入输出样例

  • 输入#1

    6
    10 3
    1 1 1 1 2 2 2 3 3 4
    6 2 2
    4 1 1
    8 2
    7 7 7 7 8 8 8 8
    4 4
    2 2
    5 1
    5 4 3 2 1
    5
    3
    7 3
    1 2 2 2 2 3 4
    1 2 4
    1 2 4
    12 7
    6 6 6 6 6 6 6 6 6 7 8 9
    2 2 2 2 2 1 1
    1 2 2 2 1 1 1
    20 2
    11 20 15 6 8 18 12 16 8 20 10 12 3 12 20 11 15 8 17 17
    8 12
    3 5

    输出#1

    1 3 4 2 1 3 
    1 1 
    2 2 
    8 7 8 7 
    8 7 8 7 
    2 4 5 3 1 
    -1
    6 6 
    7 6 
    8 6 
    9 6 
    6 6 
    6 
    6 
    12 17 20 15 8 20 16 11 
    15 20 17 12 10 8 3 18 12 11 8 6

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

首页