There are nn points in an array with index from 11 to nn, and there are two operations to those points.
1: x marking the point xx is not available
2: x query for the index of the first available point after that point (including x itself) .
unordered map要比map的查询快
#include<bits/stdc++.h>
using namespace std;
int n,m;
unordered_map<int,int> f;
int getf(int x){
if(!f.count(x))return x;
else return f[x]=getf(f[x]);
}
int main(){
scanf("%d%d",&n,&m);
int a,b;
for(int i=1;i<=m;i++){
scanf("%d%d",&a,&b);
if(a==1){
f[b]=getf(b+1);
}
else{
int ans=getf(b);
if(ans>n)ans=-1;
printf("%d\n",ans);
}
}
return 0;
}