CF1120A.Diana and Liana

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

At the first holiday in spring, the town Shortriver traditionally conducts a flower festival. Townsfolk wear traditional wreaths during these festivals. Each wreath contains exactly kk flowers.

The work material for the wreaths for all nn citizens of Shortriver is cut from the longest flowered liana that grew in the town that year. Liana is a sequence a1a_1, a2a_2, ..., ama_m, where aia_i is an integer that denotes the type of flower at the position ii. This year the liana is very long (m≥n⋅km \ge n \cdot k), and that means every citizen will get a wreath.

Very soon the liana will be inserted into a special cutting machine in order to make work material for wreaths. The machine works in a simple manner: it cuts kk flowers from the beginning of the liana, then another kk flowers and so on. Each such piece of kk flowers is called a workpiece. The machine works until there are less than kk flowers on the liana.

Diana has found a weaving schematic for the most beautiful wreath imaginable. In order to weave it, kk flowers must contain flowers of types b1b_1, b2b_2, ..., bsb_s, while other can be of any type. If a type appears in this sequence several times, there should be at least that many flowers of that type as the number of occurrences of this flower in the sequence. The order of the flowers in a workpiece does not matter.

Diana has a chance to remove some flowers from the liana before it is inserted into the cutting machine. She can remove flowers from any part of the liana without breaking liana into pieces. If Diana removes too many flowers, it may happen so that some of the citizens do not get a wreath. Could some flowers be removed from the liana so that at least one workpiece would conform to the schematic and machine would still be able to create at least nn workpieces?

春季的第一个假日,小镇肖特里弗(Shortriver)传统上会举办花节。节日期间,镇民们佩戴传统花环。每个花环恰好包含 kk 朵花。

所有 nn 位肖特里弗居民所需花环的制作材料,均取自当年在该镇生长的最长开花藤蔓。藤蔓是一个序列 a1a_1, a2a_2, ..., ama_m,其中 aia_i 是一个整数,表示位置 ii 处花朵的种类。今年这株藤蔓非常长(m≥n⋅km \ge n \cdot k),因此每位居民都能获得一个花环。

很快,藤蔓将被送入一台专用切割机,以制备花环的制作材料。该机器工作方式十分简单:它从藤蔓开头连续切下 kk 朵花,再切下另外 kk 朵花,依此类推。每一段长度为 kk 的花朵被称为一个“工件”。机器持续工作,直至藤蔓剩余花朵不足 kk 朵为止。

戴安娜(Diana)发现了一种能编织出最美丽花环的编织图样。要按此图样编织花环,所需的 kk 朵花中必须包含种类为 b1b_1, b2b_2, ..., bsb_s 的花朵,其余花朵种类可任意。若某一种类在该序列中出现多次,则该工件中对应种类的花朵数量不得少于其在序列中出现的次数。工件中花朵的排列顺序无关紧要。

戴安娜有机会在藤蔓送入切割机之前移除其中某些花朵。她可以从藤蔓的任意位置移除花朵,且不会使藤蔓断裂成多段。但如果戴安娜移除过多花朵,可能导致部分居民无法获得花环。那么,是否存在一种移除花朵的方式,使得至少有一个工件符合上述编织图样,同时切割机仍能生成至少 nn 个工件?

输入格式

The first line contains four integers mm, kk, nn and ss (1≤n,k,m≤5⋅1051 \le n, k, m \le 5 \cdot 10^5, k⋅n≤mk \cdot n \le m, 1≤s≤k1 \le s \le k): the number of flowers on the liana, the number of flowers in one wreath, the amount of citizens and the length of Diana's flower sequence respectively.

The second line contains mm integers a1a_1, a2a_2, ..., ama_m (1≤ai≤5⋅1051 \le a_i \le 5 \cdot 10^5) — types of flowers on the liana.

The third line contains ss integers b1b_1, b2b_2, ..., bsb_s (1≤bi≤5⋅1051 \le b_i \le 5 \cdot 10^5) — the sequence in Diana's schematic.

第一行包含四个整数 mm、kk、nn 和 ss(1≤n,k,m≤5⋅1051 \le n, k, m \le 5 \cdot 10^5,k⋅n≤mk \cdot n \le m,1≤s≤k1 \le s \le k):分别表示藤蔓上的花朵总数、每个花环所需的花朵数、市民人数以及黛安娜的花朵序列长度。

第二行包含 mm 个整数 a1a_1、a2a_2、...、ama_m(1≤ai≤5⋅1051 \le a_i \le 5 \cdot 10^5)——表示藤蔓上各朵花的种类。

第三行包含 ss 个整数 b1b_1、b2b_2、...、bsb_s(1≤bi≤5⋅1051 \le b_i \le 5 \cdot 10^5)——表示黛安娜设计图中的花朵序列。

输出格式

If it's impossible to remove some of the flowers so that there would be at least nn workpieces and at least one of them fullfills Diana's schematic requirements, output −1-1.

Otherwise in the first line output one integer dd — the number of flowers to be removed by Diana.

In the next line output dd different integers — the positions of the flowers to be removed.

If there are multiple answers, print any.

如果无法通过移除部分花朵,使得剩余花朵中至少存在 nn 个工件,且其中至少有一个工件满足戴安娜的设计要求,则输出 −1-1。

否则,第一行输出一个整数 dd —— 戴安娜需要移除的花朵数量。

第二行输出 dd 个互不相同的整数 —— 需要移除的花朵的位置(编号)。

若存在多个合法答案,输出任意一个即可。

输入输出样例

  • 输入#1

    7 3 2 2
    1 2 3 3 2 1 2
    2 2

    输出#1

    1
    4
  • 输入#2

    13 4 3 3
    3 2 6 4 1 4 4 7 1 3 3 2 4
    4 3 4

    输出#2

    -1
  • 输入#3

    13 4 1 3
    3 2 6 4 1 4 4 7 1 3 3 2 4
    4 3 4

    输出#3

    9
    1 2 3 4 5 9 11 12 13

说明/提示

In the first example, if you don't remove any flowers, the machine would put out two workpieces with flower types [1,2,3][1, 2, 3] and [3,2,1][3, 2, 1]. Those workpieces don't fit Diana's schematic. But if you remove flower on 44-th place, the machine would output workpieces [1,2,3][1, 2, 3] and [2,1,2][2, 1, 2]. The second workpiece fits Diana's schematic.

In the second example there is no way to remove flowers so that every citizen gets a wreath and Diana gets a workpiece that fits here schematic.

In the third example Diana is the only citizen of the town and that means she can, for example, just remove all flowers except the ones she needs.

在第一个例子中,如果不移除任何花朵,机器将输出两个工件,其花朵类型分别为 [1,2,3][1, 2, 3] 和 [3,2,1][3, 2, 1]。这些工件不符合戴安娜的设计图。但如果移除第 44 个位置上的花朵,机器将输出工件 [1,2,3][1, 2, 3] 和 [2,1,2][2, 1, 2]。第二个工件符合戴安娜的设计图。

在第二个例子中,不存在一种移除花朵的方式,使得每位市民都能获得一个花环,且戴安娜获得一个符合其设计图的工件。

在第三个例子中,戴安娜是该城镇唯一的市民,这意味着她可以(例如)仅保留自己所需花朵,而移除其余所有花朵。

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

首页