当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
What is consistent hashing?In what scenarios can it be applied?
HMS Core音频编辑服务音源分离与空间音频渲染,助力快速进入3D音频的世界
Windows 安装PostgreSQL
什么是混合元编程
JMP Pro 16.0 software installation package download and installation tutorial
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
PAT1166 Summit(25)
NebulaGraph v3.2.0 Performance Report
四足机器人软件架构现状分析
【StoneDB Class】Introduction Lesson 2: Analysis of the Overall Architecture of StoneDB
随机推荐
树和二叉树的转换
AI目标分割能力,无需绿幕即可实现快速视频抠图
leetcode:1201. 丑数 III【二分 + 数学 + 容斥原理】
2022-07-25 网工进阶(二十一)BGP-路由反射器、联盟、聚合
数字孪生北京故宫,元宇宙推进旅游业进程
What is consistent hashing?In what scenarios can it be applied?
一文带你彻底厘清 Isito 中的证书工作机制
批量任务导入到数据库中
快速理解拉格朗日乘子法
SQL function SQRT
AD单片机九齐单片机NY8B062D SOP16九齐
PAT 1167 Cartesian Tree(30)
34、树莓派进行人体姿态检测并进行语音播报
魔众文档管理系统 v5.0.0
Do wildcard SSL certificates not support multiple domains?
库函数的模拟实现(strlen)(strcpy)(strcat)(strcmp)(strstr)(memcpy)(memmove)(C语言)(VS)
让程序员早点下班的效率工具
tensorflow2.0 handwritten digit recognition (tensorflow handwriting recognition)
opencv 保存图片imwrite
芝加哥丰田技术学院 | Leveraging Natural Supervision for Language Representation Learning and Generation(利用自然监督进行语言表示学习和生成)