Codeforces Round 924 (Div. 2)B. Equalize(思维+双指针)
题面

链接
题意
给一个数组\(a\),然后让你给这个数组加上一个排列,求出现最多的次数
题解
赛时没过不应该。
最开始很容易想到要去重,因为重复的元素对于答案是没有贡献的。
去重后排序。,然后维护一个极差小于n-1的区间,,区间长度就是可能的答案。
可以用双指针去实现。
代码
#include <bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define db double
#define endl '\n'
#define x first
#define y second
#define pb push_back
using namespace std;
const int N=1e5+10;
void solve()
{
int n;cin>>n;
vector<int>a(n+1);
rep(i,1,n){
cin>>a[i];
}
sort(a.begin()+1,a.end());
set<int>s;
deque<int>q;
int ans=0;
rep(i,1,n){
while(q.size()&&a[i]-a[q.front()]>=n){
s.erase(a[q.front()]);
q.pop_front();
}
q.pb(i);
s.insert(a[i]);
int t=s.size();
ans=max(ans,t);
}
cout<<ans<<endl;
}
signed main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
// freopen("1.in", "r", stdin);
int _;
cin>>_;
while(_--)
solve();
return 0;
}
Codeforces Round 924 (Div. 2)B. Equalize(思维+双指针)的更多相关文章
- Codeforces Round #546 (Div. 2) D 贪心 + 思维
https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...
- Codeforces Round #336 (Div. 2)【A.思维,暴力,B.字符串,暴搜,前缀和,C.暴力,D,区间dp,E,字符串,数学】
A. Saitama Destroys Hotel time limit per test:1 second memory limit per test:256 megabytes input:sta ...
- Codeforces Round #541 (Div. 2) G dp + 思维 + 单调栈 or 链表 (连锁反应)
https://codeforces.com/contest/1131/problem/G 题意 给你一排m个的骨牌(m<=1e7),每块之间相距1,每块高h[i],推倒代价c[i],假如\(a ...
- Codeforces Round #541 (Div. 2) E 字符串 + 思维 + 猜性质
https://codeforces.com/contest/1131/problem/D 题意 给你n个字符串,字符串长度总和加起来不会超过1e5,定义字符串相乘为\(s*s1=s1+s[0]+s1 ...
- (原创)Codeforces Round #550 (Div. 3) D. Equalize Them All
D. Equalize Them All time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Codeforces Round #532 (Div. 2)- B(思维)
Arkady coordinates rounds on some not really famous competitive programming platform. Each round fea ...
- Codeforces Round #590 (Div. 3) A. Equalize Prices Again
链接: https://codeforces.com/contest/1234/problem/A 题意: You are both a shop keeper and a shop assistan ...
- Codeforces Round #570 (Div. 3) B. Equalize Prices
原文链接https://codeforces.com/contest/1183/problem/B 题意:进行Q组测试,在每组中有长度为n的数组a[i],然后现在给你一个K,问你找到一个bi使得|ai ...
- Codeforces Round #843 (Div. 2) C【思维】
https://codeforces.com/contest/1775/problem/C 题意 题意是说,给你n和x,你要求出最小的满足要求的m,使得 \(n\)&\((n+1)\)& ...
- Codeforces Round #469 (Div. 2)C. Zebras(思维+模拟)
C. Zebras time limit per test memory limit per test 512 megabytes input standard input output standa ...
随机推荐
- git push卡住了 git push writing object
解决方案: 执行命令:$ git config --global http.postBuffer 524288000 再次push 会卡在这里:POST git-receive-pack(892384 ...
- IdentityServer4 系列文章01---密码授权模式
IdentityServer4实现.Net Core API接口权限认证(快速入门) 什么是IdentityServer4 官方解释:IdentityServer4是基于ASP.NET Core实 ...
- 本地搭建playground
本文主要是记录我搭建go playground的步骤. 1.安装docker 如果你使用的Ubuntu,docker的安装步骤可以参见这里,这是我之前写的在Ubuntu18.04下安装fabric,其 ...
- 4款超好用的AI换脸软件,一键视频直播换脸(附下载链接)
随着AIGC的火爆,AI换脸技术也被广泛应用于娱乐.广告.电影制作等领域,本期文章系统介绍了市面上超火的4款AI软件 换脸整合包收录了全部4款AI工具,请按照需要选择下载: 百度网盘:https:// ...
- # 重要-即时通讯IM开源项目OpenIM关于版本管理及v2.3.0发布计划
越来越多的客户把OpenIM用到了生产环境,由于新特性持续迭代和bug修复,会涉及到后续的升级方案,为了让大家后续从容应对,本文重点总结OpenIM对未来版本管理的思路和方案.同时,官网对于文档进行了 ...
- 强化学习调参技巧一: DDPG算法训练动作选择边界值_分析解决
1.原因: 选择动作值只在-1 1之间取值 actor网络输出用tanh,将动作规范在[-1,1],然后线性变换到具体的动作范围.其次,tanh激活区是有范围的,你的预激活变量(输入tanh的)范围太 ...
- centos离线安装chrony
环境 CentOS Linux release 7.9.2009 (Core) 工具 chrony-2.2.1.tar.gz 下载地址:https://download.tuxfamily.org/c ...
- zblog文章采集发布插件-免费下载
推荐一款可以自动采集网页文章,并发布到zblog系统网站的zblog采集发布插件,支持简数采集器,火车头数据采集器,八爪鱼文章采集器,后羿采集器等...... zblog采集发布插件使用教程如下: 1 ...
- 在Spring Cloud 2020中使用Consul配置中心遇到的问题
升级Spring Cloud 2020后发现Consul配置中心失效了,配置中心的配置和bootstrap.yml中的配置都没有生效. 话不多说,先看官方文档:https://docs.spring. ...
- java的char类型,只有两个字节,为什么可以存储汉字?java中 char详解
我自己出了一道面试题,如下: public static void main(String[] args) { char a = '9'; char b = 9; char c = '我'; Syst ...