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 ...
随机推荐
- Mysql主从复制原理及同步延迟问题
本文转载自:Mysql主从复制原理及同步延迟问题 主从复制解决的问题 数据分布:通过复制将数据分布到不同地理位置 负载均衡:读写分离以及将读负载到多台从库 备份:可作为实时备份 高可用性:利用主主复制 ...
- Error: errCode: -404011 cloud function execution error | errMsg: clou……错误
在开通了云开发之后,无论点击小程序获取openid按钮报,Error: errCode: -404011 cloud function execution error | errMsg: clou…… ...
- os路径
import os linux下 例如: 我现在在 /home/settings.py文件下 # 获取当前的绝对路径 os.path.abspath(__file__) # 获取的内容 /home/s ...
- Scratch第四十九讲:完美的下落和反弹
做了很多小游戏,都会遇到碰撞和反弹的情况,CC哥大多时候也都是简单处理一下,包括之前的讲座也有提过,但是没有认真的讲解过.今天就专门为这个主题做一讲,把这部分内容彻底讲透,大家可以一起探讨一下. 是不 ...
- SAS学习笔记43 宏语句
流程控制 %GOTO语句与%label语句是结合起来使用的.首先通过%label语句定义一个位置,使用%GOTO语句可直接将程序的执行位置跳到该label标记位置,达到控制程序执行顺序的目的.可实现与 ...
- redis键的迁移操作
1.redis单个实例内多库间的数据迁移操作 命令名称:move 语法:move key db 功能:将当前数据库的key移动到给定的数据库db当中.如果当前数据库(源数据库)和给定数据库(目标数据库 ...
- iis 虚拟目录 文件服务器
需求 多节点站点部署时,上传文件地址统一 调整步骤如下 建立文件服务器 共享目录 设置账号密码 各服务器建账号 密码 需与文件服务器账号密码一致 调整 web.config 在<system.w ...
- MySQL INNER JOIN子句介绍
MySQL INNER JOIN子句介绍 MySQL INNER JOIN子句将一个表中的行与其他表中的行进行匹配,并允许从两个表中查询包含列的行记录. INNER JOIN子句是SELECT语句的可 ...
- RestControllerAdvice,ControllerAdvice
1.切记@RestControllerAdvice 和 @ControllerAdvice 不能放在common里,会不生效,还会引起子项目的全局异常失败. 所以这2个还是放在各自的子项目里去处理.一 ...
- EF数据Linq方式查询
using (var ctx = new NorthwindEntities()) { //单表查询SQL查询方式 //SELECT * FROM Customers AS c WHERE c.Cit ...