J.408之数据结构

J-408之数据结构_北京信息科技大学第十五届程序设计竞赛(同步赛) (nowcoder.com)

思维好题,直接用两个set存没出现的数字就好了

// Problem: 408之数据结构
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/68572/J
// Memory Limit: 524288 MB
// Time Limit: 4000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N = 1e6+10;
int n,q;
set<int>a,b;
void solve()
{
	cin>>n>>q;
	for(int i=0;i<N;i++){
		if(i&1)a.insert(i);
		else b.insert(i);
	}
	int x,mask;
	for(int i=1;i<=n;i++){
		cin>>x;
		if(a.count(x))a.erase(x);
		if(b.count(x))b.erase(x);
	}
	
	while(q--){
		int op;cin>>op;
		
		if(op==1){
			cin>>x>>mask;
			if(mask)a.erase(a.lower_bound(x));
			else b.erase(b.lower_bound(x));
		}else{
			cin>>mask;
			if(mask)cout<<*(a.begin())<<"\n";
			else cout<<*(b.begin())<<"\n";
		}
	}
	
}

int main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int _;
	_ = 1;
	while(_--)solve();
	return 0;
}

相关推荐

  1. 408数据结构专项2011

    2023-12-15 00:18:02       15 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-15 00:18:02       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-15 00:18:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-15 00:18:02       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-15 00:18:02       20 阅读

热门阅读

  1. leetcode做题笔记2048. 下一个更大的数值平衡数

    2023-12-15 00:18:02       34 阅读
  2. RESTful API,以及如何使用它构建 web 应用程序

    2023-12-15 00:18:02       31 阅读
  3. 【Python 千题 —— 基础篇】多行输出

    2023-12-15 00:18:02       41 阅读
  4. 如何在PHP中发送电子邮件?

    2023-12-15 00:18:02       47 阅读
  5. 深度解析企业私域流量的价值与构建策略

    2023-12-15 00:18:02       39 阅读
  6. 【数据库】@Transactional用法详解

    2023-12-15 00:18:02       43 阅读
  7. Mybatis-Plus同时实现分表和表内多租户模式

    2023-12-15 00:18:02       43 阅读