so easy

There are n points in an array with index from 11to n, and there are two operations to those points.

1: 1  x marking the point x is not available

2: 2 x query for the index of the first available point after that point (including x itself) .

 

Input

n     q

z1  ​x1​

.....

zq   xq

q is the number of queries, z is the type of operations, and x is the index of operations. 1≤x<n<10^9, 1< q<10^6and z is 1 or 2

Output

Output the answer for each query.

样例输入复制

5 3
1 2
2 2
2 1

样例输出复制

3
1

 因为x的取值有大数,所以用set当作hash,把删除的x都放到set里,表示被标记,然后查找的时候凡是能在set里面找到的就是被标记的,找不到的就是可以输出的。

#include<cstdio>
#include<set>
using namespace std;
 
set<int> st; 
int main(){
	
 	int n,q,z,x;
 	scanf("%d%d",&n,&q);
 	
 	while(q--){
 		
 		scanf("%d%d",&z,&x);
 		if(z==1){
 			
 		   	st.insert(x);
		 }
		else{
			
			if(st.find(x)==st.end()) 
			 printf("%d\n",x);
			else{

				do{
					x++;
					if(x==n) break;
				}while(st.find(x)!=st.end());
				
				if(x<n) printf("%d\n",x);
				
			}
		} 
 		
	 }
	
	return 0;
}

 

#include<cstdio>
#include<vector>
using namespace std;
 
vector<bool> mp(1e9+1,false); 
int main(){
	
 	int n,q,z,x;
 	scanf("%d%d",&n,&q);
 	
 	while(q--){
 		
 		scanf("%d%d",&z,&x);
 		if(z==1){
 			
 		   	mp[x]=true;
		 }
		else{
			
			if(mp[x]==false) 
			 printf("%d\n",x);
			else{

				do{
					x++;
					if(x==n) break;
				}while(mp[x]==true);
				
				if(x<n) printf("%d\n",x);
				
			}
		} 
 		
	 }
	
	return 0;
}

开头一定要记得用c++编译器,别再因为这个原因罚时。

用set可以降低内存,用vector可以暴力hash 1到1e9.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值