Description

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 k flowers.

The work material for the wreaths for all n citizens of Shortriver is cut from the longest flowered liana that grew in the town that year. Liana is a sequence a1, a2, ..., am, where ai is an integer that denotes the type of flower at the position i. This year the liana is very long (m≥n⋅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 k flowers from the beginning of the liana, then another k flowers and so on. Each such piece of k flowers is called a workpiece. The machine works until there are less than k flowers on the liana.

Diana has found a weaving schematic for the most beautiful wreath imaginable. In order to weave it, k flowers must contain flowers of types b1, b2, ..., bs, 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 n workpieces?

Input

The first line contains four integers m, k, n and s (1≤n,k,m≤5⋅105, k⋅n≤m, 1≤s≤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 m integers a1, a2, ..., am (1≤ai≤5⋅105) — types of flowers on the liana.

The third line contains s integers b1, b2, ..., bs (1≤bi≤5⋅105) — the sequence in Diana's schematic.

Output

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

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

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

If there are multiple answers, print any.

Solution

显然,删掉的数的个数是(m-kn)个

最长的序列长度就是(k+m-k
n)

O(n)求出是否有合法情况再暴力减就行了

#include <cstdio>
#include <algorithm>
#define N 500001
#define open(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
#define fo(i,a,b) for (register int i=a;i<=b;i++)
using namespace std;
int m,k,n,s,t,tot,cnt,del,len,l,r,a[N],ans[N],g[N],need[N];
bool bz[N];
void write(int x)
{
fo(i,x,x+len)
{
if (cnt==del) break;
if (g[a[i]]) g[a[i]]--;else
{
ans[++cnt]=i;
if (cnt==del) break;
}
}
printf("%d\n",del);
fo(i,1,cnt)
printf("%d ",ans[i]);
exit(0);
}
int main()
{
open("diana");
scanf("%d%d%d%d",&m,&k,&n,&s);
fo(i,1,m)
scanf("%d",&a[i]);
fo(i,1,s)
{
scanf("%d",&t);
need[t]++;
g[t]++;
if (need[t]==1) tot++;
bz[t]=1;
}
del=m-k*n;
len=del+k;
fo(i,1,len)
{
if (bz[a[i]])
{
need[a[i]]--;
if (!need[a[i]]) tot--;
}
if (!tot) write(1);
}
l=1;r=len;
fo(i,2,m-len+1)
{
if (bz[a[l]])
{
need[a[l]]++;
if (need[a[l]]==1) tot++;
}
l++;r++;
if (bz[a[r]])
{
need[a[r]]--;
if (!need[a[r]]) tot--;
}
if (!tot && !((l-1)%k)) write(i);
}
printf("-1");
return 0;
}

CF1120 A. Diana and Liana的更多相关文章

  1. 【Codeforces 1120A】Diana and Liana

    Codeforces 1120 A 题意:给\(n\)个数\(a_1..a_n\),要从其中删去小于等于\(n-m\times k\)个数,使得将这个数组分成\(k\)个一段的序列时有至少一段满足以下 ...

  2. Codeforces Round #543 Div1题解(并不全)

    Codeforces Round #543 Div1题解 Codeforces A. Diana and Liana 给定一个长度为\(m\)的序列,你可以从中删去不超过\(m-n*k\)个元素,剩下 ...

  3. Codeforces Round #539&#542&#543&#545 (Div. 1) 简要题解

    Codeforces Round #539 (Div. 1) A. Sasha and a Bit of Relax description 给一个序列\(a_i\),求有多少长度为偶数的区间\([l ...

  4. Codeforces Round #543 (Div. 1, based on Technocup 2019 Final Round) 题解

    题面戳这里 A. Diana and Liana 首先如果s>ks>ks>k一定无解,特判一下.那么我们考虑找恰好满足满足题目中的要求的区间[l,r][l,r][l,r],那么需要要 ...

  5. 记得有一个奇怪的ORA-04028: cannot generate diana for object

    开发商称新一package,目前已经在翻译过程中的一些错误.提示PL/SQL:ORA-00942: table or view does not exists.这是一个非常明显的错误,即要么是表不存在 ...

  6. 尝试造了个工具类库,名为 Diana

    项目地址: diana 文档地址: http://muyunyun.cn/diana/ 造轮子的意义 为啥已经有如此多的前端工具类库还要自己造轮子呢?个人认为有以下几个观点吧: 定制性强,能根据自己的 ...

  7. ORA-04028: cannot generate diana for object xxx

    在ORACLE数据库(10.2.0.5.0)上修改一个包的时候,编译有错误,具体错误信息为"ORA-04028: cannot generate diana for object xxx&q ...

  8. k-means|k-mode|k-prototype|PAM|AGNES|DIANA|Hierarchical cluster|DA|VIF|

    聚类算法: 对于数值变量,k-means eg:k=4,则选出不在原数据中的4个点,计算图形中每个点到这四个点之间的距离,距离最近的便是属于那一类.标准化之后便没有单位差异了,就可以相互比较. 对于分 ...

  9. DIANA算法

    DIANA算法 DIANA算法示例 DIANA算法练习

随机推荐

  1. python基础 Day4

    python Day4 1.列表 列表初识 之前的的三种str.int.bool在有的条件下不够用 str:存储少量的数据. 切片还是对其进行任何操作,获取的内容都是str类型.存储的数据单一. 列表 ...

  2. github 加速方法

    登录网址:https://github.com.ipaddress.com/codeload.github.com#ipinfo 更改hosts:

  3. linux下udev和mdev的使用

    linux下设备文件系统有devfs.udev和mdev这三种. 一.devfs devfs是由Linux 2.4内核引入的,引入时被许多工程师给予了高度评价,它的出现使得设备驱动程序能自主地管理自己 ...

  4. 操作系统-I/O(5)I/O软件的层次结构

    IO软件的设计目标: (1)高效率:改善设备效率,尤其是磁盘I/O操作的效率 (2)通用性:用统一的标准来管理所有设备 IO软件的设计思路: 把软件组织成层次结构,低层软件用来屏蔽硬件细节,高层软件向 ...

  5. JS继承 小白文

    继承我的理解是 一个对象 能够使用另一个对象的方法和属性 继承需要一个父类构造函数 一.通过原型链继承 通过 创建一个 Person 的实例对象,该对象身上 不仅有 name 和 age 等方法, 也 ...

  6. Java中抽象类和接口的介绍及二者间的区别

    接口(Interface)和抽象类(Abstract Class)是支持抽象类定义的两种机制. 一.抽象类 在Java中被abstract关键字修饰的类称为抽象类,被abstract关键字修饰的方法称 ...

  7. 基于 GitBook 搭建个人博客

    目录 基于 GitBook 搭建个人博客 1.为什么要写博客? 2.为什么选择使用 GitBook 来搭建? 3.搭建方式 3.1 GitBook 线上直接搭建 3.2 由基于Node.js的命令工具 ...

  8. Java面试题(设计模式篇+Spring/Spring MVC篇)

    设计模式 88.说一下你熟悉的设计模式? 自行熟悉. 89.简单工厂和抽象工厂有什么区别? 简单理解简单工厂:对 一个对象的创建进行封装.抽象工厂:对 一组对象的创建进行封装. 比如生产 陶瓷马 和  ...

  9. formily-面向中后台场景的复杂解决方案

    正文 在解决企业级应用的前端问题中,表单是个无法绕过的大山,正好最近有时间,调研一下 Formily-来自阿里巴巴的面向中后台复杂场景的表单解决方案,也是一个表单框架,前身是 UForm.主要解决如何 ...

  10. composer源码简单分析(一)

    composer分析(一) 本文内容 基于PSR-4规范的自动加载 请结合文档和下面的代码注释 spl_autoload_register php闭包Closure简单用法(大体使用情景: 生成回调提 ...