Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) B2. TV Subscriptions (Hard Version)
链接:
https://codeforces.com/contest/1247/problem/B2
题意:
The only difference between easy and hard versions is constraints.
The BerTV channel every day broadcasts one episode of one of the k TV shows. You know the schedule for the next n days: a sequence of integers a1,a2,…,an (1≤ai≤k), where ai is the show, the episode of which will be shown in i-th day.
The subscription to the show is bought for the entire show (i.e. for all its episodes), for each show the subscription is bought separately.
How many minimum subscriptions do you need to buy in order to have the opportunity to watch episodes of purchased shows d (1≤d≤n) days in a row? In other words, you want to buy the minimum number of TV shows so that there is some segment of d consecutive days in which all episodes belong to the purchased shows.
思路:
双指针遍历。
代码:
#include <bits/stdc++.h>
typedef long long LL;
using namespace std;
const int MAXN = 2e5+10;
int Vis[MAXN*10];
int Day[MAXN];
int n, k, d;
int main()
{
ios::sync_with_stdio(false);
int t;
scanf("%d", &t);
while (t--)
{
scanf("%d%d%d", &n, &k, &d);
for (int i = 1;i <= n;i++)
scanf("%d", &Day[i]);
for (int i = 1;i <= n;i++)
Vis[Day[i]] = 0;
int res = k, tmp = 0;
for (int i = 1;i <= d;i++)
{
if (Vis[Day[i]] == 0)
tmp++;
Vis[Day[i]]++;
}
res = min(res, tmp);
for (int i = d+1;i <= n;i++)
{
if (Vis[Day[i-d]] == 1)
tmp--;
Vis[Day[i-d]]--;
if (Vis[Day[i]] == 0)
tmp++;
Vis[Day[i]]++;
res = min(res, tmp);
}
printf("%d\n", res);
}
return 0;
}
Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) B2. TV Subscriptions (Hard Version)的更多相关文章
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2)
A - Forgetting Things 题意:给 \(a,b\) 两个数字的开头数字(1~9),求使得等式 \(a=b-1\) 成立的一组 \(a,b\) ,无解输出-1. 题解:很显然只有 \( ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) D. Power Products
链接: https://codeforces.com/contest/1247/problem/D 题意: You are given n positive integers a1,-,an, and ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) C. p-binary
链接: https://codeforces.com/contest/1247/problem/C 题意: Vasya will fancy any number as long as it is a ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) A. Forgetting Things
链接: https://codeforces.com/contest/1247/problem/A 题意: Kolya is very absent-minded. Today his math te ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) F. Tree Factory 构造题
F. Tree Factory Bytelandian Tree Factory produces trees for all kinds of industrial applications. Yo ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) E. Rock Is Push dp
E. Rock Is Push You are at the top left cell (1,1) of an n×m labyrinth. Your goal is to get to the b ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) B. TV Subscriptions 尺取法
B2. TV Subscriptions (Hard Version) The only difference between easy and hard versions is constraint ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) A. Forgetting Things 水题
A. Forgetting Things Kolya is very absent-minded. Today his math teacher asked him to solve a simple ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) D. Power Products 数学 暴力
D. Power Products You are given n positive integers a1,-,an, and an integer k≥2. Count the number of ...
随机推荐
- SQL,NoSQL和NewSQL
一:概念 SQL(Structured Query Language):数据库,指关系型数据库.主要代表:SQL Server.Oracle.MySQL.PostgreSQL. NoSQL(Not O ...
- Oracle的varchar2如何比较大小
首先要说的是Oracle中字符类型的比较都是基于ASCII码表来实现的,我就简单做个总结. Oracle中varchar2类型的字符串使用的是非填充空格的标准来进行比较的(表格中右边的那列,注意空格的 ...
- rman备份跳过read only数据文件,减少备份总量,加快备份时间
客户需求,RMAN备份时间过长,想缩短备份时间,优化备份. 客户基于表空间进行历史数据归档的方式,将历史的表空间进行read only,想让RMAN跳过只读表空间,减少RMAN备份的数据总量,从而缩短 ...
- R|批量循环处理同一格式文件-csv,txt,excel
本文首发于“生信补给站”微信公众号,https://mp.weixin.qq.com/s/8IfMrSr9xc8_1Y2_9Ne6hg 在一个文件夹下有很多字段一致,格式统一的数据文件(csv,txt ...
- MarkDown 语法记录
Markdown是一种纯文本格式的标记语言.通过简单的标记语法,它可以使普通文本内容具有一定的格式. 为啥要用 MarkDown 呢? 优点 1.因为是纯文本,所以只要支持Markdown的地方都能获 ...
- .net core 依赖注入在特性中的应用
.net core 依赖注入在特性中的应用,不知道怎么用属性注入,那么在特性中的构造函数里,怎么用接口的方法呢? 来一个简单的例子: 主要思路是把ServiceProvider 静态全局化: publ ...
- vue中子组件的created、mounted钩子中获取不到props中的值问题
父子组件通信 这个官网很清楚,也很简单,父组件中使用v-bind绑定传送,子组件使用props接收即可 例如: 父组件中: <template> <div> <head- ...
- Linux学习笔记:cut命令
基础 功能:文件内容查看,显示行中指定部分,删除文件中指定字段.cut 命令用于显示每行从开头算起 a - b 的文字. 语法: cut [-bn] [file.txt] cut [-c] [file ...
- 关于BOM的一些基本知识以及表格的操作
首先先了解什么是BOM? BOM:英文全称Browser Object Model,即浏览器对象模型.浏览器页面初始化时,会在内存创建一个全局对象,用来描述当前窗口的属性和状态,这个全局对象被称为浏览 ...
- Java 之 可变参数
可变参数 在JDK1.5之后,如果我们定义一个方法需要接受多个参数,并且多个参数类型一致,我们可以对其简化成如下格式: 修饰符 返回值类型 方法名(参数类型... 形参名){ } 其实这个书写完全等价 ...