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 ...
随机推荐
- Range Module
2019-09-21 18:54:16 715. Range Module 问题描述: 问题求解: 用线段树解决了. class RangeModule { Node root; class Node ...
- 关于getchar的疑惑
最近做了一道题,我的代码有片段是这样的 while(scanf("%d",&n)) { if(n==0&&getchar()=='\n') break; . ...
- Jenkins打造多分支流水线指南
overview: 多分支工作流程带来了以下几个关键能力: 在代码仓库中,每个新分支都有自己单独的工作流水线(job). 每个工作流水线都记录了对应分支的构建和变更历史. 可以自定义设置流水线随着分支 ...
- IOS 常用的宏定义(#define)
开发中经常用到的常量定义(随时更行): 与UIView相关 //获取View的frame属性 #define GetViewWidth(view) view.frame.size.width #def ...
- python之openpyxl模块(最全总结 足够初次使用)
openpyxl模块 Python_Openpyxl 1. 安装 pip install openpyxl 2. 打开文件 ① 创建 from openpyxl import Workbook # 实 ...
- Codeforces Global Round 7
A. Bad Ugly Numbers 思路 题意: 给我们一个k,让我们用 0-9 之间的数字构成一个 k位数a,a不能被组成a的每一位数字整除. 分析:首先 k等于1,无论我们怎么配都会被整除:当 ...
- MetaQNN : 与Google同场竞技,MIT提出基于Q-Learning的神经网络搜索 | ICLR 2017
论文提出MetaQNN,基于Q-Learning的神经网络架构搜索,将优化视觉缩小到单层上,相对于Google Brain的NAS方法着眼与整个网络进行优化,虽然准确率差了2-3%,但搜索过程要简单地 ...
- 透过源码分析ArrayList运作原理
List接口的主要实现类ArrayList,是线程不安全的,执行效率高:底层基于Object[] elementData 实现,是一个动态数组,它的容量能动态增加和减少.可以通过元素下标访问对象,使用 ...
- Java哈希表入门
Java哈希表(Hash Table) 最近做题经常用到哈希表来进行快速查询,遂记录Java是如何实现哈希表的.这里只简单讲一下利用Map和HashMap实现哈希表. 首先,什么是Map和HashMa ...
- CF633(div.2)C. Powered Addition
题目描述 http://codeforces.com/contest/1339/problem/C 给定一个长度为 \(n\) 的无序数组,你可以在第 \(x\) 秒进行一次下面的操作. 从数组选取任 ...