B2 - TV Subscriptions (Hard Version)
题目连接: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)的更多相关文章
- 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 ...
- CF1225B2 TV Subscriptions (Hard Version)
CF1225B2 TV Subscriptions (Hard Version) 洛谷评测传送门 题目描述 The only difference between easy and hard vers ...
- CF1225B1 TV Subscriptions (Easy Version)
CF1225B1 TV Subscriptions (Easy Version) 洛谷评测传送门 题目描述 The only difference between easy and hard vers ...
- 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 ...
- [CodeForces-1225B] TV Subscriptions 【贪心】【尺取法】
[CodeForces-1225B] TV Subscriptions [贪心][尺取法] 标签: 题解 codeforces题解 尺取法 题目描述 Time limit 2000 ms Memory ...
- 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 ...
- cf--TV Subscriptions (Hard Version)
time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standa ...
- CodeForces - 1214D B2. Books Exchange (hard version)
题目链接:http://codeforces.com/problemset/problem/1249/B2 思路:用并查集模拟链表,把关系串联起来,如果成环,则满足题意.之后再用并查集合并一个链,一个 ...
- 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 ...
随机推荐
- 文件解析漏洞总结(IIS,APACHE,NGINX)
(本文主体来自https://blog.csdn.net/qq_36119192/article/details/82834063) 文件解析漏洞 文件解析漏洞主要由于网站管理员操作不当或者 Web ...
- 嘉泽 P2120: 【基础】半质数 题解
原题链接 简要题意: 求区间内能分解为两个质数乘积的数. 欧拉筛先筛素数. 然后再筛答案. 时间复杂度: \(O(n)\). 实际得分:\(100pts\). #pragma GCC optimize ...
- OpenCV-Python 绘图功能 | 七
目标 学习使用OpenCV绘制不同的几何形状 您将学习以下功能:cv.line(),cv.circle(),cv.rectangle(),cv.ellipse(),cv.putText()等. 代码 ...
- Jupyter Notebook自动补全
大多数程序员都非常熟悉不同的自动补全工具.然而,我注意到许多数据科学家还没有使用它.如果你是他们中的一员,是时候开始使用这个提高效率的工具了 什么是自动补全? 它是你的编程环境提供的一种功能,用于完成 ...
- python框架-Django创建项目
创建项目 django-admin startproject douban//创建project cd douban python manage.py startapp books//创建app项目 ...
- Failed RMAN Catalog Upgrade from 11.2.0.2 to 12.1.0.2 ( ORA-02296 RMAN-06004 )
Failed RMAN Catalog Upgrade from 11.2.0.2 to 12.1.0.2 ( ORA-02296 RMAN-06004 ) 由于后期使用12c的数据库,需要对现有 ...
- unix中数据缓冲区高速缓冲的设计
目录 1. 概述 2. 缓冲区的设计 2.1 缓冲区头部 2.2 缓冲区的结构 2.3 缓冲区的检索算法 2.3. 申请一个缓冲区算法 getblk 2.3.2 释放一个缓冲区算法 brelse 2. ...
- [codevs3118]高精度除法<高精度>
题目链接:http://codevs.cn/problem/3118/ 为了做一道名为国王游戏的贪心,我跑来学习了高精度除法....相传,高精度除法是高精度四个基本运算最难的 但事实上,高精度除法可以 ...
- vulnhub~muzzybox
这个靶机是最新出的,Google了一番,发现walk trough少的可怜,最初是自己弄弄,但自己的确是菜. challenge 1.就是修改idcard.png 的内容,position princ ...
- Jenkins集成时报错 hudson.remoting.Channel$CallSiteStackTrace: Remote call to JNLP4-connect connection from xxx.xxx.xxx.xxx/xxx.xxx.xxx.xxx:32034
Started by user test Running as SYSTEM Building remotely on home_windows (mbhCloud_UI_Test) in works ...