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 ...
随机推荐
- Java基础---Java变量
变量:程序运行期间,内容可以发生改变的量. 创建一个变量并且使用的格式: 数据类型 变量名称; // 创建了一个变量 变量名称 = 数据值; // 赋值,将右边的数 ...
- Java的设计模式之开篇(1)
什么是设计模式呢?这个问题曾经一直困扰着我,以前我一直以为这是门新的技术,但是随着工作年限和工作经验的增加,其实设计模式就是已经在众多软件系统得到验证的成功的并且可复用的技术方案或者解决问题的方案.J ...
- Calibre 和 Kindle 配合的使用方法
1. 前言 使用"Calibre"软件,把网上下载的电子书转换成适合kindle阅读的格式. 2. 使用经验总结 2.1 首行缩进.段落间距设置 2.2 输出为mobi格式设置 2 ...
- glib系列2 APP编译
编译命令 gcc main.c `pkg-config --cflags glib-2.0 --libs glib-2.0` 头文件 $ ls /usr/local/include/glib-2.0/ ...
- asp.net core-11.WebHost的配置
1.添加空的web网站 ,在目录下添加settings.json文件,在控制台上输出json的信息 public class Program { public static void Main(str ...
- QMetaEnum获取枚举元信息
QMetaEnum 类提供了一个枚举的元数据.我们可以使用该类的静态模板函数,fromType<enumerator>来获得关于某个枚举的QMetaEnum对象,然后就可以调用该类的成员函 ...
- JSP JSONArray使用遇坑!添加以下6个jar包
1.JAR包简介 要使程序可以运行必须引入JSON-lib包,JSON-lib包同时依赖于以下的JAR包: commons-lang.jar commons-beanutils.jar commons ...
- Google Drive 和 Dropbox 同步同一个文件夹目录
Dropbox 也是非常棒的同步工具,例如先进的增量上传或者更开放的 API 等.可是为什么不曾想过把 Google Drive 和 Dropbox 同时使用呢,我是说,让这两者同时云同步同一个文件 ...
- Android Parcelable 序列化复杂数据结构
参考博文 http://blog.csdn.net/yangzl2008/article/details/7593226 由于项目需要,Activity之间要传递一个特别复杂的数据结构对象,由于以前序 ...
- 使用url_for()时,会自动调用转换器的to_url()方法
视图反推url,在动态url(转换器)反推中的应用 # -*- coding: utf-8 -*- from flask import Flask, url_for, redirect from we ...