链接:

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)的更多相关文章

  1. 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. 题解:很显然只有 \( ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

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

  8. 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 ...

  9. 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 ...

随机推荐

  1. hdu 6153 思维+扩展kmp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6153 扩展kmp不理解的看下:http://www.cnblogs.com/z1141000271/p ...

  2. 西门子软件sinutrain-for-sinumerik-operate-v4.8安装报错的处理

       西门子软件sinutrain-for-sinumerik-operate-v4.8安装报错的处理 安装时报错提示: 原因: 可能缺少某些文件 处理: 安装 海康ivms-4200后,可直接安装西 ...

  3. (二)发布第一个WebService服务与DSWL文档解析

    1. 编写接口 package service; import javax.jws.WebService; /** * 第一个webservice服务, * @WebService注解表示这是一个we ...

  4. Java垃圾回收机制(GC策略)

    Java垃圾回收机制(GC策略) 核心:1,哪些是垃圾?[怎么确定这个是垃圾]:2,如何回收垃圾?[怎么更好收垃圾]. Java语言相对于C++等语言有一个自动垃圾回收机制,只用管使用[实例化对象], ...

  5. Swagger 实践 <二>

    1. 新建.netCore WebApi 项目(选择Angular).按照上一篇的加上Swage 文档,使http://localhost:11934/swagger/v1/swagger.json  ...

  6. 微软升级 WSL Window Subsystem for Linux Win10系统自带Linux

    在设计之初,微软就允许类似于Win32这种子系统运行于windows NT内核之上,它可以为上层应用提供编程接口,同时避免应用去实现内核里的一些调用细节.NT内核的设计在最开始就可以支持POSIX,O ...

  7. redis数据结构分析 (redisObject、SDS)

    redis是一个key-value储存系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sorted set ...

  8. Redis二进制安全概念

    二进制安全是指,在传输数据时,保证二进制数据的信息安全,也就是不被篡改.破译等,如果被攻击,能够及时检测出来. 二进制安全包含了密码学的一些东西,比如加解密.签名等. 举个例子,你把数据1111000 ...

  9. 编译和执行 C# 应用程序

  10. [杭电oj][1005]Number Sequence

    sky同学在努力地刷题..,在这题卡住了,于是一起研究了一下... 这题本身挺简单的,(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) m ...