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

什么是混合元编程

What is consistent hashing?In what scenarios can it be applied?

【StoneDB Class】Introduction Lesson 2: Analysis of the Overall Architecture of StoneDB

「计算复杂性」理论奠基人Juris Hartmanis逝世,曾获93年图灵奖

响应式2022英文企业官网源码,感觉挺有创意的

OpenSSL SSL_read: Connection was reset, errno 10054

论文详读《基于改进 LeNet-5 模型的手写体中文识别》,未完待补充

【2022蓝帽杯】file_session && 浅入opcode

批量替换Word中的表格为图片并保存

多线程案例——阻塞式队列
随机推荐
ECCV 2022|R2L: 用数据蒸馏加速NeRF
【每日一题】592. 分数加减运算
DDL和DML的含义与区别「建议收藏」
微服务原生案例搭建
Efficiency tools to let programmers get off work earlier
A Beginner's Guide to Performance Testing
LeetCode_动态规划_中等_313.超级丑数
The obstacles to put Istio into production and how we solve them
How to Integrate Your Service Registry with Istio?
PanGu-Coder:函数级的代码生成模型
ABC260 E - At Least One (Dual Pointer)
PyTorch 进阶之路:在 GPU 上训练深度神经网络
消息中间件解析 | 如何正确理解软件应用系统中关于系统通信的那些事?
Why does the maximum plus one equal the minimum
拥抱NFV,Istio 1.1 将支持多网络平面
NebulaGraph v3.2.0 性能报告
透过开发抽奖小程序,体会创新与迭代
NFV迈向云原生时代:Network Service Mesh项目介绍
力扣160题,相交链表
【每日一题】593. 有效的正方形