Codeforces Round #357 (Div. 2) C. Heap Operations(模拟,优先队列)

uni-app - 修改默认端口,H5 项目控制台运行出来的 IP 地址的默认端口号(H5 项目运行后控制台,修改项目运行到内置浏览器默认 8080 端口号) uni-app运行到H5修改默认端口号,uni-app如何修改默认端口,uni-app修改默认端口,uni-app本地运行修改调试已上线微信H5项目,请问在UNIAPP的H5运行调试时候的IP是否可以自己设置固定,uni-app开发环境,如何设置h5服务器的端口,uni-app如何修改默认端,uni-app修改默认端口,uni-app指定端口号,uni-app-修改H5项目控制台运行出来的IP地址的默认端口号(H5项目运行后控制台,修改项目运行到内置浏览器默认8080端口号) 阅读详情

三个操作,简单模拟,让不合法的操作变成合法即可。


  • insert x — put the element with value x in the heap;
  • getMin x — the value of the minimum element contained in the heap was equal to x;
  • removeMin — the minimum element was extracted from the heap (only one instance, if there were many).


代码:

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6+5;
string cmd[maxn];
int num[maxn];

int main(void)
{
    int n;
    while(cin >> n)
    {
        priority_queue<int, vector<int>, greater<int> > pq;
        int cur = 0;
        while(n--)
        {
            int val;
            string temp;
            cin >> temp;
            if(temp[0] == 'r')
            {
                if(pq.empty())
                {
                    cmd[cur] = "insert ";
                    num[cur++] = 0;
                    cmd[cur++] = "removeMin";
                }
                else pq.pop(), cmd[cur++] = "removeMin";
            }
            else if(temp[0] == 'i')
            {
                scanf("%d", &val);
                pq.push(val);
                cmd[cur] = "insert ";
                num[cur++] = val;
            }
            else
            {
                scanf("%d", &val);
                while(!pq.empty() && pq.top() < val)
                {
                    cmd[cur++] = "removeMin";
                    pq.pop();
                }
                if(pq.empty() || pq.top() > val)
                {
                    pq.push(val);
                    cmd[cur] = "insert ";
                    num[cur++] = val;
                }
                cmd[cur] = "getMin ";
                num[cur++] = val;
            }
        }
        printf("%d\n", cur);
        for(int i = 0; i < cur; i++)
        {
            cout << cmd[i];
            if(cmd[i][0] == 'r') printf("\n");
            else printf("%d\n", num[i]);
        }
    }
    return 0;
}



C. Heap Operations
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Petya has recently learned data structure named "Binary heap".

The heap he is now operating with allows the following operations:

  • put the given number into the heap;
  • get the value of the minimum element in the heap;
  • extract the minimum element from the heap;

Thus, at any moment of time the heap contains several integers (possibly none), some of them might be equal.

In order to better learn this data structure Petya took an empty heap and applied some operations above to it. Also, he carefully wrote down all the operations and their results to his event log, following the format:

  • insert x — put the element with value x in the heap;
  • getMin x — the value of the minimum element contained in the heap was equal to x;
  • removeMin — the minimum element was extracted from the heap (only one instance, if there were many).

All the operations were correct, i.e. there was at least one element in the heap each time getMin or removeMin operations were applied.

While Petya was away for a lunch, his little brother Vova came to the room, took away some of the pages from Petya's log and used them to make paper boats.

Now Vova is worried, if he made Petya's sequence of operations inconsistent. For example, if one apply operations one-by-one in the order they are written in the event log, results of getMin operations might differ from the results recorded by Petya, and some ofgetMin or removeMin operations may be incorrect, as the heap is empty at the moment they are applied.

Now Vova wants to add some new operation records to the event log in order to make the resulting sequence of operations correct. That is, the result of each getMin operation is equal to the result in the record, and the heap is non-empty when getMin ad removeMinare applied. Vova wants to complete this as fast as possible, as the Petya may get back at any moment. He asks you to add the least possible number of operation records to the current log. Note that arbitrary number of operations may be added at the beginning, between any two other operations, or at the end of the log.

Input

The first line of the input contains the only integer n (1 ≤ n ≤ 100 000) — the number of the records left in Petya's journal.

Each of the following n lines describe the records in the current log in the order they are applied. Format described in the statement is used. All numbers in the input are integers not exceeding 109 by their absolute value.

Output

The first line of the output should contain a single integer m — the minimum possible number of records in the modified sequence of operations.

Next m lines should contain the corrected sequence of records following the format of the input (described in the statement), one per line and in the order they are applied. All the numbers in the output should be integers not exceeding 109 by their absolute value.

Note that the input sequence of operations must be the subsequence of the output sequence.

It's guaranteed that there exists the correct answer consisting of no more than 1 000 000 operations.

Examples
input
2
insert 3
getMin 4
output
4
insert 3
removeMin
insert 4
getMin 4
input
4
insert 1
insert 1
removeMin
getMin 2
output
6
insert 1
insert 1
removeMin
removeMin
insert 2
getMin 2
Note

In the first sample, after number 3 is inserted into the heap, the minimum number is 3. To make the result of the first getMin equal to 4one should firstly remove number 3 from the heap and then add number 4 into the heap.

In the second sample case number 1 is inserted two times, so should be similarly removed twice.



YOLO26优化:原创自研 | 自研独家创新DSAM注意力 ,基于BiLevelRoutingAttention注意力升级 提出新颖的注意力DSAM(Deformable Bi-level SpatialAttention Module),创新度极佳,适合科研创新,效果秒杀CBAM,Channel Attention+Spartial Attention升级为新颖的Deformable Bi-level Attention+Spartial Attention 阅读详情

相关推荐

生态位宽度计算&可视化展示(R语言)

物种的生态位越宽,该物种的特化程度就越小,倾向于泛化种(generalist species);物种的生态位越窄,倾向于是一个特化种(specialists species)。生态位宽度是指物种(或其它生物单位)在群落中所利用的各种不同资源的总和。本篇所使用为生态位宽度指数即**Levins的生态位宽度指数。

weixin_53705272的博客 4445

swagger报错 :No operations defined in spec! 解决方法

No operations defined in spec问题解决方法 问题 swagger2在爆出这个No operations defined in spec! 错误,第一步说明你的swagger的配置是正确的,没有受到拦截器的拦截,项目里面的报出的错误No operations defined in spec! 的 原因是包没有扫到。 解决方法 把需要扫的包指给swagger就可以,一般有如下几种情况: 类上没有没有添加Api注解方法没有添加ApiOperation注解 import io.swa

柳牧之的博客 3万+

深入探讨 VQ-VAE:理解变分量化自动编码器

VQ-VAE代表"Variational Quantized Variational Autoencoder",是一种生成模型,通常用于处理高维数据,如图像和音频。它的设计灵感来自于变分自动编码器(VAE)和量化方法,结合了它们的优点,使得 VQ-VAE 能够生成高质量的数据,并在数据表示上引入离散性。VQ-VAE 是一种强大的生成模型,结合了变分自动编码器和量化方法的优点。它在图像和音频生成、数据压缩和生成性对抗网络等领域具有广泛的应用。

DeepViewInsight的博客 7021

swagger 出现No operations defined in spec! 以及包配置与@ComponentScan注解冲突解决

swagger配置的包名与@Component注解会起冲突导致出现:No operations defined in spec!

weixin_54867893的博客 4357

Android13 CarPowerManagementService onApPowerStateChange流程分析

如下为CarPower上电的流程图:下面我们从代码角度分析:在CPMS的init方法中会调用onApPowerStateChange(CpmsState.WAIT_FOR_VHAL, CarPowerManager.STATE_WAIT_FOR_VHAL); 设置ApPowerState为STATE_WAIT_FOR_VHAL: 在onApPowerStateChange中调用PowerHandler 的handlePowerStateChange方法: 在handlePowerStateChang

liuning1985622的博客 934

COMSOL实现裂缝性储层油水两相流模拟的关键技术

多孔介质中的流体流动模拟是油气藏开发的核心技术,其基本原理基于达西定律和质量守恒方程。在裂缝性储层中,离散裂缝网络与基质系统的耦合流动带来了特殊的数值挑战。通过COMSOL Multiphysics平台实现的多物理场耦合技术,可以精确模拟油水两相在复杂裂缝系统中的渗流行为。该技术采用Level Set方法表征裂缝几何形态,结合自适应网格生成技术解决狭窄裂缝的网格剖分难题,并创新性地引入Bang-Larsen毛管压力滞后模型,显著提高了采收率预测精度。这些方法在致密油藏开发、水驱优化等工程实践中具有重要应用价

weixin_34005090的博客 235

swagger 报 No operations defined in spec!

swagger 报 No operations defined in spec!

weixin_43652507的博客 3595

麒麟信安3.3-6C电网版虚拟机安装避坑指南:从ISO下载到SSH配置全流程

本文提供麒麟信安3.3-6C电网版虚拟机的详细安装与配置指南。针对电力行业仿真测试需求,重点解析从ISO镜像获取、虚拟机环境准备、安装过程中的三大“雷区”(如多管理员密码逻辑、分区方案、网络配置)到首次启动后的网络、SSH及root策略配置的全流程避坑要点,帮助技术人员高效、安全地完成部署。

rainy的博客 862

Swagger出现No operations defined in spec问题排查

今天想将项目集成一下Swagger但是却出现了提示No operations defined in spec的问题,没有扫描到对应的接口以下是我的排查顺序,希望能够帮助到大家: 1. 首先检查Swagger的配置文件是否出现问题: /** * Swagger配置类 */ @Configuration @EnableSwagger2 @Profile({"dev", "test"}) // produce环境禁用swagger public class SwaggerConfig { @Bean

Mats的博客 8856

iTunes登录协议抓包实战:绕过反检测与TLS解密的完整方案

在软件逆向与网络协议分析中,抓包工具扮演着关键角色。代理型工具如Fiddler通过修改系统代理实现HTTPS解密,而驱动型工具如HTTPDebugger则注入进程钩取网络API,但这些实现机制往往会被具有反检测策略的客户端识别。以iTunes登录协议为例,其内置证书锁定、进程完整性与系统代理检测等防护,导致常规抓包方案失效。从工具原理出发,对比不同抓包方案的暴露面,重点介绍如何利用Fiddler通过中间人代理获取明文流量,以及使用Wireshark进行被动监听规避检测的进阶技巧,并总结常见问题排查经验,为分

weixin_28607671的博客 371

【Cadence软件技巧集萃】从Capture到Allergo——分布演示从原理符号导出到网络表

Cadence软件功能多样、性能强大,但是使用起来颇费步骤,尤其是从原理图到网络表的导入步骤,没有经过上手实践还真不一定一次就能搞定哩。本文笔者用将分步演示:1、在Capture软件上绘制原理图;2、将原理图导出网络表;3、在Allergo软件上更新网络表;希望给予使用Cadence的读者有效的帮助1、本文简述了建立Capture项目的步骤,演示了调用元件符号库的方法,并绘制了电气原理图;2、针对加载元件封装库可能遇到的问题,做了排查步骤建议;

qq_33175704的博客 2545

swagger报No operations defined in spec亲测的完美解决方案

四、在启动类上加上@ComponentScan注解,然后将swagger公共类的路径和自己Controller层的路径放上去,重新启动项目就可以访问到swagger页面。一、进入swagger时报No operations defined in spec!三、查看swagger公共类中的标红的地址是不是指向自己的Controller层。二、检查pom.xml文件。

weixin_45230325的博客 4469

UDPProbe UDP端口存活探测(发送特征包+响应分析)、UDP服务识别

qDebug() << "收到响应:" << ip.toString() << ":" << port << " 服务:" << serviceName << " 响应长度:" << response.size();qDebug() << "开始探测:" << targetIp << ":" << port << " 超时时间:" << timeout << "ms";qInfo() << "\n==================== UDP探测结果 ====================";

寒寒豆豆软件公司的博客 158

Codeforces Round #357 (Div. 2) C.Heap Operations 优先队列 + 模拟

C. Heap Operations 题目链接 Petya has recently learned data structure named "Binary heap". The heap he is now operating with allows the following operations: put the given number into ...

dexicuo5991的博客 165

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

Codeforces Round #357 (Div. 2 ) C. Heap Operations 优先队列模拟

Petya has recently learned data structure named “Binary heap”. The heap he is now operating with allows the following operations: put the given number into the heap; get the value of the minimum el...

loooooog的博客 179

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

Codeforces Round #357 (Div. 2) -- C. Heap Operations (优先队列模拟)

C. Heap Operations time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Petya has recently learned data structure named "Bi

aozil_yang的博客 484

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

Codeforces Round #357 (Div. 2) C. Heap Operations (优先队列)

C. Heap Operations time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Petya has recently learned data structure named "Bi

滴水穿石,慢慢积累,总会有成果 670

Codeforces Round #357 (Div. 2) C. Heap Operations 优先队列

&#13; C. Heap Operations&#13; 链接:&#13; http://codeforces.com/contest/681/problem/C&#13; 题意:&#13; 共有3种指令,1:insert x,插入一个值x,2:getMin x,在集合中得到最小值x,3:removeMin,从集合中移除最小值,现在给你n项指令,但其中有缺项,现在让你补全这...

花海 146

Codeforces Round #357 (Div. 2)C. Heap Operations(优先队列)

Heap Operations(优先队列)

m0_74113129的博客 160

Codeforces Round #357 (Div. 2) C Heap Operations (模拟)

题意:给你一些堆操作,但这是不完全的,可能有漏的,你需要补漏,也就是加上最少的操作使得整个操作序列合法。 题解:我们用一个优先队列来维护, a、insert就直接push进去; b、getMin的话,分两种情况:1、队列为空,那么插入一个数即可,2、不空即看最开头的元素,如果小于x的话就pop出来(记得加操作),循环知道队列为空或者最开头的元素大于等于x,如果大于或者为空的话就要先inser

Ezereal的博客 415

Codeforces Round #357 (Div. 2)C:Heap Operations

C. Heap Operations time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Petya has recently learned data structure

加载中... 739

Codeforces Round #357 (Div. 2) C Heap Operations(模拟)

思路:开个优先队列模拟一下即可,注意一下细节 #include using namespace std; priority_queue,greater >q; vector >ans; char s[30]; int main() { int n; scanf("%d",&n); for(int i = 0;i<n;i++) { int p; sc

围巾的ACM博客 747

Codeforces Round #357 (Div. 2) C. Heap Operations(优先队列)

题目地址:http://codeforces.com/problemset/problem/681/C 思路:优先队列模拟,注意判断队列为空,若删除时为空,先加入0再删除。 #include #include #include #include #include #define debu using namespace std; const int INF=1e9+1; int n; vect

哆啦AC梦的博客 479

Codeforces Round #357 (Div. 2)C. Heap Operations

用单调队列(从小到大),模拟一下就好了,主要是getMin比较麻烦,算了,都是模拟。。。。也没什么好说的。。#include<cstdio> #include<map> #include<queue> #include<iostream> #include<stdlib.h> #include<string.h> #include<algorithm> using namespace std;pri

ONE MORE TRY 538

Codeforces Round #357 (Div. 2) C. Heap Operations 模拟

C. Heap Operations 题目连接: http://www.codeforces.com/contest/681/problem/C Description Petya has recently learned data structure named "Binary heap". The heap he is now operating with allows the followi...

weixin_34274029的博客 238

Codeforces Round #357 (Div. 2)-C. Heap Operations(优先队列)

C. Heap Operations time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Petya has recently learned data structure

信仰.的博客 561
上一篇: hdoj 2209 翻纸牌游戏(翻转问题)
下一篇: Codeforces Round #378 (Div. 2) C. Epidemic in Monstropolis(模拟)
cillyb
博客等级 码龄11年 225粉丝 497原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值