题目连接: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. [ICRA 2019]Multi-Task Template Matching for Object Detection, Segmentation and Pose Estimation Using Depth Images

    简介         本文作者提出新的框架(MTTM),使用模板匹配来完成多个任务,从深度图的模板上找到目标物体,通过比较模板特征图与场景特征图来预测分割mask和模板与检测物体之间的位姿变换.作者提 ...

  2. 图论-完全二叉树判定-Check Completeness of a Binary Tree

    2020-02-19 13:34:28 问题描述: 问题求解: 判定方式就是采用层序遍历,对于一个完全二叉树来说,访问每个非空节点之前都不能访问过null. public boolean isComp ...

  3. 刷oj之类的题时java Scanner读取太慢解决之道

    1.转载自一个 https://www.cpe.ku.ac.th/~jim/java-io.html 2.工具代码 class Reader { static BufferedReader reade ...

  4. (数据科学学习手札81)conda+jupyter玩转数据科学环境搭建

    本文示例yaml文件已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 我们在使用Python进行数据分析时,很 ...

  5. Feign客户端的重构,新建springcloud架构

    1,在上篇博文中,已经实现了feign 客户端来远程调用接口的功能,因为feign 客户端在springcloud 开发过程中是比较常用的方式 https://www.cnblogs.com/pick ...

  6. HTTP 请求状态码

    200    请求成功 304    从缓存中读取 302 + 响应头中定义location: 重定向 // 自定义重定向 @RequestMapping("/customRedirecti ...

  7. Thread ---java 内存模型

    1,Java 线程之间的通信由Java 内存模型(JMM)控制.JMM决定一个线程对共享变量的写入时,能对另一个线程可见. 从抽象的角度来看,JMM定义了线程和主内存之间的抽象关系: 线程之间的共享变 ...

  8. 11g数据库使用DBUA升级Exadata数据库至12c

    DB Name: GRPSource DB: 11.2.0.3  Target DB: 12.1.0.2 11g数据库使用DBUA升级Exadata数据库至12c前提条件: 0.需要11g源数据库fu ...

  9. AOJ 2214: Warp Hall(计数+dp)

    题目链接 题意 有一个 \(N × M\) 的二维平面, 平面上有 k 对虫洞, \(N, M ≤ 1e5, k ≤ 1e3\). 每对虫洞具有坐标 \(x_1, y_1, x_2, y_2\), 满 ...

  10. VLAN基础

    VLAN(Virtual Local Area Network)的中文名为"虚拟局域网".是将一个物理的局域网在逻辑上划分成多个广播域,从而实现二层隔离的技术. 一.VLAN的优点 ...