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 ...
随机推荐
- ABP Vnext 微服务 常见问题
1.token问题 原因:拿token和认证token的服务器不一致 2.minio访问报错 minio错误 S3 API Request made to Console port. S3 R 解决方 ...
- Windows 10 关闭搜索栏中“热门搜索”的显示。
Windows 10 关闭搜索栏中"热门搜索"的显示. 任务栏取消"显示搜索突出显示"的设置可能无法取消"热门搜索"的显示, 这就需要您尝试 ...
- C/C++ 实现切片免杀的思路
今天突然想到了一个好玩的免杀思路,原理就是想办法切断磁盘特征与内存特征,关于沙盒免杀我寻思着,这样可以将不同的的DLL映射到内存,在内存中他们的特征也是被切断的,在注入器上做判断如果是沙盒则不加载,不 ...
- Django后台输出原生SQL语句
如果需要打印orm翻译后的原生sql语句,只需要在setting最后加上下面代码就行. 1 LOGGING = { 2 'version': 1, 3 'disable_existing_logger ...
- cs50ai2
cs50ai2-------Uncertainty cs50ai2-------Uncertainty 基础知识 课后题目 代码实践 学习链接 总结 基础知识 在这节课中,前面主要介绍了一些概率论的基 ...
- Linux反空闲的设置和关闭
有一定工作经验的运维人基本都会遇到这样的场景,某个窗口自动断开了,提示超时: [oracle@jystdrac1 ~]$ timed out waiting for input: auto-logou ...
- .NET Core开发实战(第35课:MediatR:让领域事件处理更加优雅)--学习笔记
35 | MediatR:让领域事件处理更加优雅 核心对象 IMediator INotification INotificationHandler 这两个与之前的 Request 的行为是不一样的, ...
- 深入浅出 Application Insights--学习笔记
摘要 介绍如何将 Application Insights 用于生产上实践,并透过它发现/诊断问题.同时也会介绍如何将 Application Insighs 与其他体系相集成实现 Devops(与发 ...
- UVA1108 Mining Your Own Business 题解
题目传送门 题意 在一个无向图上选择尽量少的点涂黑,使得删除任意一个点后,每个连通分量里都至少有一个黑点(多组数据). 正文 观察题意,发现这是个 Tarjan 求点双连通分量的板子. 考虑在求点双连 ...
- PyOCD Notes
Installation Ubuntu20.04 For Ubuntu20.04 the version in apt repository is 0.13.1+dfsg-1, which is to ...