A.Diana and Liana

题目链接在此!

这题也是心理变态出的。头疼!

A.Diana and Liana(CodeForces 1121D)
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.

Examples Input 7 3 2 2 1 2 3 3 2 1 2 2 2 Output 1 4 Input 13 4 3 3 3
2 6 4 1 4 4 7 1 3 3 2 4 4 3 4 Output
-1 Input 13 4 1 3 3 2 6 4 1 4 4 7 1 3 3 2 4 4 3 4 Output 9 1 2 3 4 5 9 11 12 13 Note In the first example, if you don’t remove any flowers,
the machine would put out two workpieces with flower types [1,2,3] and
[3,2,1]. Those workpieces don’t fit Diana’s schematic. But if you
remove flower on 4-th place, the machine would output workpieces
[1,2,3] and [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.

题目大意:

n 朵花,每连续的 k 朵 可以组成一个花环。
组成共 m 个花环,其中一个花环中的 s 朵花必须满足给定的序列(接着给出s朵花的种类)。
也就是说,其中一个连续 k 朵花组成的花环中必须包含那 s 种花。
求出最大可以删除的花朵,并输出这些花的坐标。
答案不唯一,输出任意一个。

题意分析:

明显是尺取算法。
想起前段时间有人和我说尺取的时候打成吃蛆,这也太恐怖了。
我的想法是:
等同于
len = n - k * m + k;
尺取区间的最大长度是:
最多删除的花朵数量(总量-花环)+一只花环需要的数量。
ans=这个区间删除 n-m*k 朵多余的花
del = n - k * m;
从开头维护一个长度为 len 的区间[l,r]看符不符合题意,不符合就往后一个一个挪动,更新左右端点以及挪动造成的影响。

还有一点,虽然其它花环没有特殊要求,但也必须是连续的 k 个才能组成花环。所以,这个区间外左右两边必须都是 k 的倍数。

感觉思路写的还是很清楚的。

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <cmath>
#include <map>
#include <unordered_map>
#include <iomanip>#define INF 0x3f3f3f3f
#define pi acos(-1)
#define M 110
using namespace std;
typedef long long ll;using namespace std;
const int maxn = 5e5 + 10;int a[maxn];
int need[maxn] = {0};
int cnt[maxn] = {0};
int ans[maxn] = {0};
bool vis[maxn] = {0};
//经典大数组放外面int main() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int n, k, m, s;cin >> n >> k >> m >> s;for (int i = 1; i <= n; i++)cin >> a[i];int len = n - k * m + k;//尺取区间int del = n - k * m;//这些在思路里都写的很清楚了int kinds = 0;for (int i = 1; i <= s; i++) {int temp;cin >> temp;if (!need[temp])//如果还没标记过{vis[temp] = 1;//标记一下此种花需要kinds++;//需要的花种类变多}++need[temp];}bool flag = 0;//判断循环结束int L = 1;for (int i = 1; i <= len; i++)//第一个区间{int temp = a[i];cnt[temp]++;if (vis[temp] && cnt[temp] == need[temp])kinds--;if (kinds == 0) {L = 1;flag = 1;break;//刚好第一个区间就满足}}if (!flag)for (int i = len + 1; i <= n; i++) {int l = a[L];//储存上一个区间最左int r = a[i];//储存上一个区间最左L++;cnt[l]--;//最左边的花没了。if (vis[l])//最左边的花是需要的{if (cnt[l] == need[l] - 1)//刚刚好去掉左边那朵就不够了的时候才会导致数量++//不然便是之前就不够or少了一朵也没关系kinds++;}cnt[r]++;//最右边的花多了if (vis[r])//最右边的花是需要的{if (cnt[r] == need[r])kinds--;}if (kinds == 0 && (L - 1) % k == 0)
//思路里分析过的,只要判断左端点即可,因为区间大小特别。{flag = 1;break;}}int num = 0;if (flag)
//有解{for (int i = L; i < len + L; i++) {//此为解所在区间int temp = a[i];if (need[temp] > 0) {need[temp]--;continue;//不能被删掉}if (num == del) break;//被删掉的数量应该刚好等于delans[++num] = i;}cout << num << endl;for (int i = 1; i <= num; i++) {if(i!=num) cout << ans[i] << ' ';else cout << ans[num] << endl;}} else cout << -1 << endl;return 0;
}

感觉写的好清楚了。

#11.11 个人排位赛round2_A.Diana and Liana(CodeForces 1121D)相关推荐

  1. 云顶之弈服务器维护多长时间,云顶之弈维护到几点结束 2021最新11.11版本维护公告...

    许多云顶之弈的玩家都会发现,今天打开云顶之弈游戏之后进不去了,这是因为云顶之弈游戏今天举行了停机维护,将会为玩家更新11.11版本,11.11版本更新之后,又会为游戏中的内容带来许多的变化,许多阵容的 ...

  2. 2016 ACM / ICPC Asia dalian Regional Contest 题解(11 / 11)【每日亿题2021 / 2 / 17】

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A .(2017 ACM ICPC dalian H)To begin or not to be ...

  3. 京东11.11大促背后,那些系统架构经历了些什么

    一年一度的京东11.11电商大促,是一次用户的狂欢,也是一次京东智联云架构师们的大型测验.在海量流量.高频用户访问和大量不确定性的DDos攻击之下,系统架构面临了太多考验.在今年京东11.11期间,京 ...

  4. 京东11·11:撬动数据中心的支点——京东阿基米德

    今年11.11,京东数据中心操作系统(JDOS)阿基米德已经全面接管了应用资源调度.每日调度百万台容器实例运转,每日为离线计算提供了多达3000万核·小时的计算资源,SLA履约率达到98.3%.在保证 ...

  5. 京东全球购11·11战报:面膜售出430万片,爽肤水销售额是同期7倍

    伴随京东11·11全球好物节高潮到来,京东全球购发布了11月1日至10日的销售数据,整体大牌人气再度攀升,各品牌销量均取得大幅增长.数据显示,11月1日至10日,京东全球购面膜累计销售达430万片,苹 ...

  6. 【11/11】模拟赛

    官方的链接:http://www.byvoid.com/blog/byvoid-wow-stage-3/ 本博客不再给出题目. 第一题 彩色穿孔卡片 用的O(N^2)的算法.类似USACO的浮水法. ...

  7. 1号店11.11:分布式搜索引擎的架构实践

    http://www.uml.org.cn/zjjs/201512011.asp "11.11"是一年一度的电商盛宴,为了准备这个一年内最大规模的促销,1号店各条战线都在紧张有序地 ...

  8. 11.10/11.11/11.12 安装PHP5 11.13 安装PHP7

    2019独角兽企业重金招聘Python工程师标准>>> 11.10/11.11/11.12 安装PHP5 PHP官网www.php.net 当前主流版本为5.6/7.1 安装前请安装 ...

  9. websocket实现多屏互动_“京东11.11直播超级夜”正式官宣,跨屏互动新玩法燃爆11.11...

    10月27日,京东直播正式宣布将于11月10日晚8点在北京五棵松凯迪拉克中心举办"京东11.11直播超级夜".该晚会将由亚洲顶级制作团队操刀,超30位重磅明星倾情奉献,通过京东直播 ...

最新文章

  1. 再见,Teamviewer!这款国产轻量级远程桌面软件超牛逼!
  2. python资料百度云-Java+Python+前端 学习资料大全 百度云盘
  3. 关于DJANGO和JAVASCRIPT的时间
  4. 1022 词法分析程序总结
  5. java分布式对象RMI应用测试用例
  6. Windows下redis使用及安装
  7. cad怎么选择一个对象打散vba_CAD制图的二十四字秘诀!
  8. 云服务和硬件成微软业绩新增长点
  9. 最短路径之弗洛伊德算法
  10. PHP 7天前的时间戳
  11. numpy教程:函数库和ufunc函数
  12. eNSP模拟器中 FTP 实验
  13. 试用SVO_edgelet
  14. 给小朋友讲故事——第一次世界大战(音频)
  15. 2014 年最热门的国人开发开源软件 TOP 100 - 开源中国社区
  16. 沉痛悼念游戏开发技术专家毛星云(网名“浅墨”)
  17. 字体设计中的表现手法(一)
  18. 5G纯干货|毫米波概述与优缺点
  19. 本人大一的课程设计,时间太长,代码可能有些许丢失,欢迎纠错
  20. 【关于简历】——-从简历看出一个人的性格

热门文章

  1. python扇贝课程_“学点Python吧,别再这么累了。”
  2. 嵌入式Linux系统镜像制作(基于SD卡)
  3. Blender插件开发:bpy.utils模块
  4. ASWEET项目实施日志
  5. 《Android自定义控件》RulerView,仿唯品会身高、体重等标尺,尺码控件,滑动可修改刻度值
  6. 如何判断车距:车距判断技巧图解
  7. 泰克mdo3014使用手册_泰克示波器MDO3014故障维修案例分享
  8. windows无法连接到打印机_同事的电脑无法访问,共享打印机连接不上,问题都在这...
  9. 计算机一级期末考试题,2016年计算机一级考试题库(含答案)
  10. C语言中转义字符的介绍与使用