链接:

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. java源码 -- LinkedHashMap

    一.概述 LinkedHashMap 继承自 HashMap,在 HashMap 基础上,通过维护一条双向链表,解决了 HashMap 不能随时保持遍历顺序和插入顺序一致的问题. 除此之外,Linke ...

  2. 20191011-构建我们公司自己的自动化接口测试框架-TestData的数据准备

    创建excel测试数据准备,excel的第一个sheet存储测试集,后面分别为测试用例和断言结果表 测试集构成如下: 按列分别为测试序号,测试用例说明,对应的sheetname,测试用例是否允许,测试 ...

  3. YAML 语言格式

    1. 认识 YAML YAML(Yet Another Markup Language)语言(发音 /ˈjæməl/ )是一个类似 XML.JSON 的标记性语言.YAML 强调以数据为中心,并不是以 ...

  4. Python操作Redis(转)

    原文1:https://cloud.tencent.com/developer/article/1151834 原文2:https://www.cnblogs.com/zhaohuhu/p/91406 ...

  5. C# EF & linq 常用操作

    一.EF的左连接 在EF中,当在dbset使用join关联多表查询时,连接查询的表如果没有建立相应的外键关系时,EF生成的SQL语句是inner join(内联),对于inner join,有所了解的 ...

  6. Nopcommerce4.2解析——安装

    Nopcommerce是一个DotNet领域异常凶残的一个开源电商系统,最先版本4.2,下面我们会逐步分析他的各个模块,为我们的二次开发做准备,应该会写一个系列. 首次运行nop页面会自动跳转到安装页 ...

  7. VBA if...elseif...else语句

    一个If语句,后面可以跟一个或多个由布尔表达式组成的elseif语句,然后是一个默认的else语句,当所有条件变为false时执行else语句块. 语法 以下是VBScript中If...Elseif ...

  8. canvas验证码实现

    1 <!DOCTYPE html> <html> <!-- head --> <head> <meta charset="utf-8&q ...

  9. js实现千位分隔符

    var s=123456789; var seperate=s.toString().replace(/\B(?=(\d{3})+$)/g,',');

  10. BP神经网络—java实现

    神经网络的结构 神经网络的网络结构由输入层,隐含层,输出层组成.隐含层的个数+输出层的个数=神经网络的层数,也就是说神经网络的层数不包括输入层.下面是一个三层的神经网络,包含了两层隐含层,一个输出层. ...