当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

10年稳定性保障经验总结,故障复盘要回答哪三大关键问题?|TakinTalks大咖分享

免费使用高性能的GPU和TPU—谷歌Colab使用教程

四足机器人软件架构现状分析

Qt实战案例(55)——利用QDir删除选定文件目录下的空文件夹

数字孪生北京故宫,元宇宙推进旅游业进程

windows IDEA + PHP+xdebug 断点调试

搭建LNMT架构

How does the SAP ABAP OData service support the Create operation trial version

使用open3d可视化3d人脸

HMS Core音频编辑服务音源分离与空间音频渲染,助力快速进入3D音频的世界
随机推荐
Multithreading Case - Timer
【StoneDB Class】Introduction Lesson 2: Analysis of the Overall Architecture of StoneDB
快速幂---学习笔记
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
芝加哥丰田技术学院 | Leveraging Natural Supervision for Language Representation Learning and Generation(利用自然监督进行语言表示学习和生成)
态路小课堂丨浅谈优质光模块需要具备的条件!
windows IDEA + PHP+xdebug 断点调试
华盛顿大学、Allen AI 等联合 | RealTime QA: What's the Answer Right Now?(实时 QA:现在的答案是什么?)
关于Request复用的那点破事儿。研究明白了,给你汇报一下。
[Cloud Enjoying Freshness] Community Weekly Vol.73- DTSE Tech Talk: 1 hour in-depth interpretation of SaaS application system design
LeetCode_位运算_简单_405.数字转换为十六进制数
PanGu-Coder:函数级的代码生成模型
【每日一题】592. 分数加减运算
8. SAP ABAP OData 服务如何支持创建(Create)操作
脚本语言Lua的基础知识总结
What is consistent hashing?In what scenarios can it be applied?
34、树莓派进行人体姿态检测并进行语音播报
How to integrate 3rd party service center registration into Istio?
10年稳定性保障经验总结,故障复盘要回答哪三大关键问题?|TakinTalks大咖分享
Qt实战案例(55)——利用QDir删除选定文件目录下的空文件夹