Insert or Erase

2024-03-10 21:20
文章标签 insert erase

本文主要是介绍Insert or Erase,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

https://atcoder.jp/contests/abc344/tasks/abc344_e

给一个不含重复数字的数组,两个询问。

1 x y:在x后面插入一个数y

2 x:删除x

#include<iostream>
#include<map>
using namespace std;
map<int,int> l,r;
void insert(int x,int y,int c){l[c]=x;r[c]=y;l[y]=c;r[x]=c;
}
void del(int x){l[r[x]]=l[x];r[l[x]]=r[x];
}
int main(){int n;cin>>n;int sd=-1e9-10,ed=1e9+10;int ll=sd,rr=ed;r[sd]=ed,l[ed]=sd;for(int i=1;i<=n;i++){int x;cin>>x;insert(ll,rr,x);ll=x,rr=r[x];}int q;cin>>q;while(q--){int op,x,y;cin>>op;if(op==1){cin>>x>>y;ll=x,rr=r[x];insert(ll,rr,y);}else{cin>>x;del(x);}}for(int i=r[sd];i!=ed;i=r[i]) cout<<i<<' ';cout<<endl;return 0;
}

这篇关于Insert or Erase的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/795549

相关文章

Hibernate插入数据时,报错:org.springframework.dao.DataIntegrityViolationException: could not insert: [cn.itc

在用junit测试:插入数据时,报一下错误: 错误原因: package junit;import org.junit.Test;import cn.itcast.crm.container.ServiceProvinder;import cn.itcast.crm.dao.ISysUserDao;import cn.itcast.crm.domain.SysRole;

C++ emplace emplace_back是什么 替代 insert

在C++开发过程中,我们经常会用STL的各种容器,比如vector,map,set等,这些容器极大的方便了我们的开发。在使用这些容器的过程中,我们会大量用到的操作就是插入操作,比如vector的push_back,map的insert,set的insert。这些插入操作会涉及到两次构造,首先是对象的初始化构造,接着在插入的时候会复制一次,会触发拷贝构造。但是很多时候我们并不需要两次构造带来效率的

C++ set find erase 报错 崩溃

不是find报错,而是访问find之后的迭代器或者erase,报错崩溃。 这是因为可能find出来的元素不存在,所以需要先判断一下。

SQLite Insert 语句:一场数据“移民”大作战

SQLite Insert 语句:一场数据“移民”大作战 嘿,各位数据库的“移民官”们!今天咱们来聊聊SQLite里的一场有趣活动——Insert语句,也就是数据“移民”。没错,就像国家与国家之间有移民,我们的数据也可以在SQLite数据库的各个表之间“移民”。 一、Insert语句的“移民签证” 在SQLite这个“国家”里,想要让数据“移民”到另一个表,你需要给它们办理一张“移民签证”,

07-2. Insert or Merge (25)

07-2. Insert or Merge (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue According to Wikipedia: Insertion sort iterates, consuming one input eleme

MySQL的INSERT ··· ON DUPLICATE KEY UPDATE使用的几种案例和说明

准备工作: 创建一张表,联合主键: create table test_insert_on_duplicate_key_update(id tinyint unsigned not null,birth_day date not null,score int unsigned not null,primary key(id, birth_day)) engine = InnoDB;

数据世界的新篇章:精通INSERT INTO数据插入艺术

标题:数据世界的新篇章:精通INSERT INTO数据插入艺术 在数据库管理的宏伟画卷中,INSERT INTO语句扮演着至关重要的角色。它是将新数据记录插入到表中的基石。本文将带领你深入理解INSERT INTO语句的精髓,并通过丰富的代码示例,展示如何运用这一功能将数据准确无误地嵌入到数据库中。 1. INSERT INTO的基本概念 INSERT INTO是SQL语言中用于向数据库表中

Leetcode81: Search Insert Position

Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assume no duplicates in the array.

Erase/Trim/Discard/Sanitize

针对JEDEC协议中几个抹除资料的命令,大家都很容易将其混淆。现在就这四个抹除命令作详细介绍,希望能帮助大家分清各个命令的具体含义及用法。 Erase 1.1擦除组(EraseGroup) Erase翻译过来是抹去、擦除的意思。eMMC中可擦除的单位称为“擦除组”,擦除组是用写入块(writeblocks,Device的基本可写单位)来测量的。擦除组的大小是一个设备特殊参数,当ERASE

Mybatis Java代码中执行insert后,就能获取到主键id的配置方法

环境 Java:1.8+ mybatis:3.3.0 mybatis-generator-core:1.3.5 配置 //keyColumn是指定主键用的,如果表中<insert id="insertSelective" parameterType="com.sgy.Tag"keyProperty="id" keyColumn="id" useGeneratedKeys="true"><