链接:

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;
}

最新文章

  1. Boost.Python简介
  2. linux进程通信之使用匿名管道进行父子进程通信
  3. 芯航线FPGA学习套件之多通道串行ADDA(TLV1544,TLC5620)模块测试手册
  4. jQuery form插件的使用--用 formData 参数校验表单,验证后提交(简单验证).
  5. Codeforces Round #215 (Div. 1) B
  6. 【.NET应用技巧】Asp.NET MVC 4 设置IIS下调试
  7. Moutain Tai notes
  8. Liers 树状数组+中国剩余定理
  9. TensorFlow 实战之实现卷积神经网络
  10. handsontable 常用 配置项 笔记
  11. 利用api模拟百度搜索功能
  12. 百战程序员9- IO流
  13. Go指南练习_切片
  14. 观察者模式——Head First
  15. spring 事务传播 never 当一个业务方法设置为never时候表示 不会加入任何事务中
  16. FreeSWITCH网关参数之caller-id-in-from
  17. Java通过复选框控件数组实现添加多个复选框控件
  18. wcf服务查看工具
  19. 五子棋项目总结 JavaScript+jQuery(插件写法)+bootstrap(模态框)
  20. vscode和phpStorm使用xdebug调试设置

热门文章

  1. Time &amp; Space Complexity
  2. MySQL和Oracle的区别与不同
  3. jenkinsFile harbor docker优化版
  4. GB2312、GBK、GB18030 这几种字符集的主要区别
  5. 变量————if语句——结构使用
  6. uboot 添加自定义命令
  7. SpringCloud Eureka 配置
  8. MVC5项目转.Net Core 2.2学习与填坑记录(1)
  9. linux安装tmux分屏插件
  10. PHP代码多人开发