2019/12/05 CF-1265-B Beautiful Numbers

Codeforces Round #604 (Div. 2)

题目链接:http://codeforces.com/contest/1265/problem/B

测试样例:

input
3
6
4 5 1 3 2 6
5
5 3 1 2 4
4
1 4 3 2

output
101011
11111
1001

AC代码:

#include<bits/stdc++.h>
using namespace std;
const int maxn=2*1e5+5;
int mark[maxn];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            int x;
            scanf("%d",&x);
            mark[x]=i;
        }
        int l=n+1,r=-1;
        for(int i=1;i<=n;i++)
        {
            l=min(l,mark[i]),r=max(r,mark[i]);
            if(r-l+1==i)
                printf("1");
            else
                printf("0");
        }
        printf("\n");
    }
    return 0;
}
发布了26 篇原创文章 · 获赞 1 · 访问量 442

猜你喜欢

转载自blog.csdn.net/qq_45309822/article/details/103450995