题目连接:https://codeforces.com/contest/1247/problem/B2

题解:双指针,,一个头,一个尾,头部进入,尾部退出,一开始先记录1到k,并记录每个数字出现的次数,然后在头进尾出,依次判断。

#include<bits/stdc++.h>
using namespace std;
const int N=2E5+;
map<int ,int >mp;
int arr[N];
void solve(){
mp.clear();
int n,m,k;
cin>>n>>m>>k;
for(int i=;i<=n;i++) scanf("%d",&arr[i]);
int ans=;
for(int i=;i<=k;i++){
if(mp[arr[i]]==) ans++;
mp[arr[i]]++;
}
int sum=ans;
for(int j=k+,i=;j<=n;j++,i++){
if(mp[arr[i]]==) ans--;
mp[arr[i]]--; if(mp[arr[j]]==) ans++;
mp[arr[j]]++;
sum=min(ans,sum);
}
cout<<sum<<endl;
}
int main(){
int t;
cin>>t;
while(t--) solve();
return ;
}

B2 - TV Subscriptions (Hard Version)的更多相关文章

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

  2. CF1225B2 TV Subscriptions (Hard Version)

    CF1225B2 TV Subscriptions (Hard Version) 洛谷评测传送门 题目描述 The only difference between easy and hard vers ...

  3. CF1225B1 TV Subscriptions (Easy Version)

    CF1225B1 TV Subscriptions (Easy Version) 洛谷评测传送门 题目描述 The only difference between easy and hard vers ...

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

  5. [CodeForces-1225B] TV Subscriptions 【贪心】【尺取法】

    [CodeForces-1225B] TV Subscriptions [贪心][尺取法] 标签: 题解 codeforces题解 尺取法 题目描述 Time limit 2000 ms Memory ...

  6. Codeforces Round #599 (Div. 2) B2. Character Swap (Hard Version) 构造

    B2. Character Swap (Hard Version) This problem is different from the easy version. In this version U ...

  7. cf--TV Subscriptions (Hard Version)

    time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standa ...

  8. CodeForces - 1214D B2. Books Exchange (hard version)

    题目链接:http://codeforces.com/problemset/problem/1249/B2 思路:用并查集模拟链表,把关系串联起来,如果成环,则满足题意.之后再用并查集合并一个链,一个 ...

  9. Codeforces Round #590 (Div. 3) B2. Social Network (hard version)

    链接: https://codeforces.com/contest/1234/problem/B2 题意: The only difference between easy and hard ver ...

随机推荐

  1. 2017-12-08高级.net 面试小结

    现在思维是企业级开发思维 应该往互联网思维转变,主要涉及,队列 ,消息,数据并发,数据安全,前端,vue,element UI 以下为速8酒店笔试题 1.有如下代码: string s1;string ...

  2. sql-lib闯关1-10关

    闯关之前我们需要搭建所需环境SQLi-Labs SQLi-Labs是一个专业的SQL注入练习平台,该平台包含了以下在测试场景中常见的注入类型: 1.报错注入(联合查询) ​     1)字符型 ​   ...

  3. Android菜单(menu)

    Android  菜单 我们继续来进行学习,今天写一下在软件中用的还算较多的菜单. 1.Menu 菜单,很显然,作用就是点击不同的选项触发不同的方法.现在在安卓使用中推荐使用ActionBar,但这里 ...

  4. Python第六章-函数05-迭代器&生成器

    python作为一个既面向对象,又支持函数式编程的语言,函数的使用方面有很多特点. 比如:闭包,装饰器,迭代器等 函数的高级应用 容器:生活中常见的容器有哪些?袋子,盆子,水杯,书包,铅笔盒... 容 ...

  5. 【Pytest03】全网最全最新的Pytest框架fixture应用篇(1)

    fixtrue修饰器标记的方法通常用于在其他函数.模块.类或者整个工程调用时会优先执行,通常会被用于完成预置处理和重复操作.例如:登录,执行SQL等操作. 完整方法如下:fixture(scope=' ...

  6. linux部署win服务 dotnet mono jexus

    .Net Core (dotnet C#应用) dotnet 可以用在linux上运行 C#应用 适用于 SSO 统一身份认证系统 # 安装依赖 yum install libunwind yum i ...

  7. java单元/集成测试中使用Testcontainers

    1.Testcontainers介绍: Testcontainers是一个Java库,它支持JUnit测试,提供公共数据库.SeleniumWeb浏览器或任何可以在Docker容器中运行的轻量级.一次 ...

  8. .net core系统跨平台部署手册

    前言 .net core跨平台版本基于.net core 3.1 SDK开发,剥离原来的基于MS Office进行文档转换功能的模块,使用基于开源跨平台的LibreOffice进行文档转换的模块.以此 ...

  9. Linux - Ubuntu18.04下更改apt源为阿里云源

    进入apt目录,备份原来的源地址 cd /etc/apt mv ./source.list ./source.list.bak 修改源文件source.list vim source.list 更换阿 ...

  10. 【原创】Linux RCU原理剖析(一)-初窥门径

    背景 Read the fucking source code! --By 鲁迅 A picture is worth a thousand words. --By 高尔基 说明: Kernel版本: ...