题目连接: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. POJ1780 欧拉路+手写栈解决爆战问题

    题目链接:http://poj.org/problem?id=1780 本题中给出一个位数n,要求给出一个10^n+n-1位数的数,要求每个n位的数都要在里面出现,一个n位的数一共有10^n种,我们容 ...

  2. xmake v2.3.2 发布, 带来和ninja一样快的构建速度

    这个版本重点重构优化了下内部并行构建机制,实现多个target间源文件的并行编译,以及并行link的支持,同时优化了xmake的一些内部损耗,修复影响编译速度的一些bug. 通过测试对比,目前的整体构 ...

  3. 安装自动化测试工具webdriver与selenium模块

    webdriver是一个驱动,需要与selenium配合使用,selenium是自动化测试和爬虫的专业模块,对于不同的浏览器需要不同的webdriver,这里我用的是ubuntu19.10的系统,以p ...

  4. leetcode 签到 914. 卡牌分组

    题目 给定一副牌,每张牌上都写着一个整数. 此时,你需要选定一个数字 X,使我们可以将整副牌按下述规则分成 1 组或更多组: 每组都有 X 张牌. 组内所有的牌上都写着相同的整数. 仅当你可选的 X ...

  5. 六、深浅拷贝与while循环

    一.深浅拷贝 3.1 浅copy: 浅copy是把原列表第一层的内存地址不加区分完全copy一份给新列表 用法: list1=[ 'egon', 'lxx', [1,2] ] list2=list1. ...

  6. 谷歌2019 学术指标发榜:CVPR首次进入Top 10,何恺明论文引用最高!

    [导读]今天,谷歌发布了2019最新版学术指标,对收录的会议和期刊的影响力进行排名.AI类的多个顶会进入榜单Top 100,CVPR更是进入前10,而何恺明的"深度残差网络"单篇引 ...

  7. Python第七章-面向对象高级

    面向对象高级 一. 特性 特性是指的property. property这个词的翻译一直都有问题, 很多人把它翻译为属性, 其实是不恰当和不准确的. 在这里翻译成特性是为了和属性区别开来. 属性是指的 ...

  8. 面试刷题28:如何写出安全的java代码?

    对jdk,jvm,java应用程序的攻击多种多样?那么从java程序员的角度,如何写出安全的代码呢? 我是李福春,我在准备面试,今天的题目是:如何写出安全的java代码? 答:这个需要从功能设计到实现 ...

  9. 上传到码云时遇到:Incorrect username or password ( access token )

    由于之前上传到 码云时候使用命令:git push -u origin master时出现如下bug Incorrect username or password ( access token ) 时 ...

  10. 使用tensorflow实现cnn进行mnist识别

    第一个CNN代码,暂时对于CNN的BP还不熟悉.但是通过这个代码对于tensorflow的运行机制有了初步的理解 ''' softmax classifier for mnist created on ...