有 ñ指向数组,索引来自1到n,这些点有两个操作。
1:1 x 标记点x不可用
2: 2 x 查询该点之后的第一个可用点的索引(包括Xx本身)。
输入
ñ q
Z1 X1
.
.
.
Zq Xq
q是查询的数量,z是操作的类型,x是操作索引。1≤x<N <10 ^ 9, 1≤X<ñ<10 ^ 9,Z取值为1或2
输出
输出每个查询的答案。
样例输入
5 3
1 2
2 2
2 1
样例输出
3
1
ac代码:
/*ac代码一*/
#include<stdio.h>
#include<iostream>
#include<set>
using namespace std;
int main(){
int n,x;
int q;
int z;
scanf("%d%d",&n,&q);
set<int> s;
for(int i=0;i<q;i++){
scanf("%d%d",&z,&x);
if(z==1){
s.insert(x);
}
else if(z==2){
int f=0;
set<int>::iterator it;
do{
it=s.find(x);
if(it==s.end()) {
f=1;
break;
}
x++;
if(x==n) break;
}while(it!=s.end());
if(f==1)
printf("%d\n",x);
}
}
return 0;
}
/*ac代码二*/
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<bool>a(1e9+1,true);
int n,q;
scanf("%d%d",&n,&q);
while(q--)
{
int z,x;
scanf("%d%d",&z,&x);
if(z==1)
{
a[x]=false;
}
else
{
while(x<=n)
{
if(a[x]==true)
{
printf("%d\n",x);
break;
}
else
x++;
}
if(x>n)
printf("-1\n");
}
}
return 0;
}