2652: 数组操作
Result | TIME Limit | MEMORY Limit | Run Times | AC Times | JUDGE |
---|---|---|---|---|---|
![]() | 3s | 32768K | 438 | 52 | Standard |
对于一个长度为n,初始化为0的数组,定义如下操作。
S x 找出下标大于等于x的第一个值为0的元素,并输出其下标。
M x 将x标记为1
现在给出m次操作,请输出每次操作之后的结果。
注意数组的下标从0开始。
Input
多组输入,每组如下:
n,m (1<=n<=1000000,1<=m<=100000)
以下m行。如果是S x。你需要输出选择的下标(不存在输出-1)。
如果是M x (0<=x<=n-1)。你需要将下标为x的元素标记为1。不输出。
n=m=0表示输入结束。
Output
对于每个S x。输出一行。
Sample Input
10 5 M 4 S 4 S 0 M 0 S 0
Sample Output
5 0 1
#include<stdio.h>
int a[1000001],b[1000001];
int main()
{
char ch;
int x,n,m;
while(scanf("%d%d ",&n,&m)!=EOF)
{
if(n==0&&m==0) break;
for(int i=0;i<n;i++) b[i]=i;
for(int i=0;i<m;i++)
{
scanf("%c ",&ch);
scanf("%d ",&x);
if(ch=='S')
{
bool flag=false;
if(b[x]==x)
{
printf("%d/n",x);
flag=true;
}
int temp=b[x];
while(!flag&&temp<n)
{
if(b[temp]==temp)
{
printf("%d/n",temp);
flag=true;
}
temp=b[temp];
}
if(!flag) printf("-1/n");
}
else
b[x]=x+1;
}
}
return 0;
}