当前位置:网站首页>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;
}
边栏推荐
- 牛客刷SQL--6
- The obstacles to put Istio into production and how we solve them
- 【每日一题】952. 按公因数计算最大组件大小
- How to Integrate Your Service Registry with Istio?
- 数据挖掘-04
- 28uA待机8米距离低压保护单片机探头太阳能灯人体PIR定制方案
- tensorflow2.0 handwritten digit recognition (tensorflow handwriting recognition)
- 34、树莓派进行人体姿态检测并进行语音播报
- Qt实战案例(56)——利用QProcess实现应用程序重启功能
- AD单片机九齐单片机NY8B062D SOP16九齐
猜你喜欢
让程序员早点下班的效率工具
响应式2022英文企业官网源码,感觉挺有创意的
预防和制止家庭暴力 人身安全保护令司法解释今起施行
207.数组序号转换
全球都热炸了,谷歌服务器已经崩掉了
shell 中的 分发系统 expect脚本 (传递参数、自动同步文件、指定host和要传输的文件、(构建文件分发系统)(命令批量执行))
JMP Pro 16.0 software installation package download and installation tutorial
性能测试入门指南
Yann LeCun开怼谷歌研究:目标传播早就有了,你们创新在哪里?
Qt实战案例(55)——利用QDir删除选定文件目录下的空文件夹
随机推荐
8. SAP ABAP OData 服务如何支持创建(Create)操作
Multi-threaded cases - blocking queue
数字孪生北京故宫,元宇宙推进旅游业进程
LeetCode_动态规划_中等_313.超级丑数
PAT 1163 Dijkstra Sequence(30)
sql is not null 优化(oracle语句索引优化)
拥抱NFV,Istio 1.1 将支持多网络平面
牛客刷SQL--7
PyTorch 进阶之路:在 GPU 上训练深度神经网络
Why does the maximum plus one equal the minimum
华盛顿大学、Allen AI 等联合 | RealTime QA: What's the Answer Right Now?(实时 QA:现在的答案是什么?)
热心肠:关于肠道菌群和益生菌的10个观点
搭建LNMT架构
高仿项目协作工具【Worktile】,从零带你一步步实现组织架构、网盘、消息、项目、审批等功能
Qt实战案例(56)——利用QProcess实现应用程序重启功能
消息中间件解析 | 如何正确理解软件应用系统中关于系统通信的那些事?
What Can Service Mesh Learn from SDN?
微服务原生案例搭建
iframe tag attribute description detailed [easy to understand]
tensorflow2.0手写数字识别(tensorflow手写体识别)