当前位置:网站首页>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+小程序开发者背后的数据库降本增效实践
- 8. SAP ABAP OData 服务如何支持创建(Create)操作
- Grafana 9.0 released, Prometheus and Loki query builders, new navigation, heatmap panels and more!
- 牛客刷SQL--4
- 软件测试之发现和解决bug
- 数据挖掘-04
- windows IDEA + PHP+xdebug 断点调试
- 动态库、静态库浅析
- 2022-07-29 网工进阶(二十二)BGP-其他特性(路由过滤、团体属性、认证、AS欺骗、对等体组、子路由器、路由最大接收数量)
- PAT 1167 Cartesian Tree(30)
猜你喜欢

全链路灰度在数据库上我们是怎么做的?

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

PAT 1167 Cartesian Tree(30)
![leetcode: 1201. Ugly Number III [Dichotomy + Mathematics + Inclusion and Exclusion Principle]](/img/44/bf1d9b9d85939e73bc44be2f9701e1.png)
leetcode: 1201. Ugly Number III [Dichotomy + Mathematics + Inclusion and Exclusion Principle]

leetcode:1201. 丑数 III【二分 + 数学 + 容斥原理】

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

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

Programmer's Romantic Tanabata

PAT 1163 Dijkstra Sequence(30)

Multi-threaded cases - blocking queue
随机推荐
响应式2022英文企业官网源码,感觉挺有创意的
什么是一致性哈希?可以应用在哪些场景?
易优压双驱挖掘机压路机器类网站源码 v1.5.8
windows IDEA + PHP+xdebug 断点调试
8. How does the SAP ABAP OData service support the Create operation
关于Request复用的那点破事儿。研究明白了,给你汇报一下。
PIR人体感应AC系列感应器投光灯人体感应开关等应用定制方案
程序员的浪漫七夕
全球都热炸了,谷歌服务器已经崩掉了
CCS软件安装教程(超级详细)「建议收藏」
leetcode:1201. 丑数 III【二分 + 数学 + 容斥原理】
PyTorch 进阶之路:在 GPU 上训练深度神经网络
微服务系统架构的演变
How do we do full-link grayscale on the database?
代理商替代义隆153 Aip4210
Istio投入生产的障碍以及如何解决这些问题
动态库、静态库浅析
D - Draw Your Cards(模拟)
LeetCode_动态规划_中等_377.组合总和 Ⅳ
高仿项目协作工具【Worktile】,从零带你一步步实现组织架构、网盘、消息、项目、审批等功能