当前位置:网站首页>D - Draw Your Cards (Simulation)
D - Draw Your Cards (Simulation)
2022-08-01 13:45:00 【Harris-H】
D - Draw Your Cards(模拟)
用一个setMaintain the number of heap tops corresponding to all current heaps.
每次lowerbound找,If there is, insert it into the header with a linked list.开一个数组记录cnt.
如果cnt=k,Then iterate over to update the answer,然后从setdelete the top of the heap.
Each element is traversed at most once and removed once.
时间复杂度: 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;
}
边栏推荐
- 50W+小程序开发者背后的数据库降本增效实践
- 2022-07-29 网工进阶(二十二)BGP-其他特性(路由过滤、团体属性、认证、AS欺骗、对等体组、子路由器、路由最大接收数量)
- sql is not null 优化(oracle语句索引优化)
- 【每日一题】1161. 最大层内元素和
- Six Stones Programming: Problems must be faced, methods must be skillful, and functions that cannot be done well must be solved
- leetcode: 1201. Ugly Number III [Dichotomy + Mathematics + Inclusion and Exclusion Principle]
- A Beginner's Guide to Performance Testing
- 批量替换Word中的表格为图片并保存
- 透过开发抽奖小程序,体会创新与迭代
- 什么是元编程
猜你喜欢
随机推荐
【每日一题】593. 有效的正方形
态路小课堂丨浅谈优质光模块需要具备的条件!
D - Draw Your Cards(模拟)
数据挖掘-03
NFV迈向云原生时代:Network Service Mesh项目介绍
【每日一题】1331. 数组序号转换
Qt实战案例(55)——利用QDir删除选定文件目录下的空文件夹
全球都热炸了,谷歌服务器已经崩掉了
Programmer's Romantic Tanabata
芝加哥丰田技术学院 | Leveraging Natural Supervision for Language Representation Learning and Generation(利用自然监督进行语言表示学习和生成)
How to Integrate Your Service Registry with Istio?
【无标题】
shell 中的 分发系统 expect脚本 (传递参数、自动同步文件、指定host和要传输的文件、(构建文件分发系统)(命令批量执行))
脚本语言Lua的基础知识总结
iPhone难卖,被欧洲反垄断的服务业务也难赚钱了,苹果的日子艰难
formatdatetime function mysql (date sub function)
tensorflow2.0手写数字识别(tensorflow手写体识别)
207.数组序号转换
线上问题排查常用命令,总结太全了,建议收藏!!
使用open3d可视化3d人脸









