当前位置:网站首页>D - Draw Your Cards(模拟)
D - Draw Your Cards(模拟)
2022-08-01 13:22:00 【Harris-H】
D - Draw Your Cards(模拟)
用一个set维护当前所有堆对应的堆顶数。
每次lowerbound找,如果有则用链表插到表头。开一个数组记录cnt。
如果cnt=k,则遍历更新答案,然后从set里删掉堆顶。
每个元素最多遍历一次删除一次。
时间复杂度: O ( n l o g n ) O(nlogn) O(nlogn)
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int n,k,ans[N],cnt[N],to[N];
set<int>s;
int main()
{
scanf("%d%d",&n,&k);
memset(ans,-1,sizeof(ans));
for(int i=1,x;i<=n;i++)
{
scanf("%d",&x);
auto it=s.lower_bound(x);
if(it==s.end())s.insert(x),cnt[x]=1;
else cnt[x]=cnt[*it]+1,to[x]=*it,s.erase(it),s.insert(x);
if(cnt[x]==k)
{
for(int j=x;j;j=to[j])ans[j]=i;
s.erase(s.find(x));
}
}
for(int i=1;i<=n;i++)printf("%d\n",ans[i]);
return 0;
}
边栏推荐
猜你喜欢
207.数组序号转换
安全又省钱,“15岁”老小区用上管道燃气
PanGu-Coder:函数级的代码生成模型
Based on 10 years of experience in stability assurance, what are the three key questions to be answered in failure recovery?|TakinTalks big coffee sharing
魔众短链接系统 v3.9.0
台积电认清了形势,新的建厂计划没有美国,中国芯片也得到重视
什么是混合元编程
论文笔记All about Eve: Execute-Verify Replication for Multi-Core Servers
【2022蓝帽杯】file_session && 浅入opcode
关于Request复用的那点破事儿。研究明白了,给你汇报一下。
随机推荐
微信UI在线聊天源码 聊天系统PHP采用 PHP 编写的聊天软件,简直就是一个完整的迷你版微信
快速理解拉格朗日乘子法
markdown常用数学符号cov(markdown求和符号)
LeetCode_动态规划_中等_313.超级丑数
一文带你彻底厘清 Kubernetes 中的证书工作机制
Grafana 9.0 released, Prometheus and Loki query builders, new navigation, heatmap panels and more!
28uA待机8米距离低压保护单片机探头太阳能灯人体PIR定制方案
MySQL调优
观察者模式
数据挖掘-04
HMS Core音频编辑服务音源分离与空间音频渲染,助力快速进入3D音频的世界
The basic knowledge of scripting language Lua summary
态路小课堂丨浅谈优质光模块需要具备的条件!
8. SAP ABAP OData 服务如何支持创建(Create)操作
数字孪生北京故宫,元宇宙推进旅游业进程
【StoneDB Class】Introduction Lesson 2: Analysis of the Overall Architecture of StoneDB
使用ffmpeg来查看视频的信息,fps,和width,height
Istio Pilot代码深度解析
Six Stones Programming: Problems must be faced, methods must be skillful, and functions that cannot be done well must be solved
高仿项目协作工具【Worktile】,从零带你一步步实现组织架构、网盘、消息、项目、审批等功能