Beautiful Numbers

传送门

题意

对于数m,若存在l,r,使得[pl,pl+1…pr]为1-m的排列,则m是beautiful number。从1到n,若是
则输出1否则输出0.

思路

显然1是满足的,而m要满足条件则1-m的数的最大下标与最小下标的差为m-1。
可以用两个数来存当前的最大最小下标,从2-n顺序遍历。

代码

#include <iostream>
#include <cstring>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <cstdio>
#include <queue>
#include <sstream>
#include <string>
#include <algorithm>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define reps(i, a, b) for (int i = a; i >= b; i--)
using namespace std;
const int N = 2e5 + 7;
const int M = 1e2 + 7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
typedef long long ll;
int a[N];
int pos[N];
void solve(int n)
{
    rep(i,1,n){
        scanf("%d",&a[i]);
        pos[a[i]]=i;//记录每个数对应的下标
    }
    int l=pos[1],r=pos[1];//1是满足的,所以l,r初始化为1的下标
    printf("1");
    rep(i,2,n){//从2开始
        l=min(l,pos[i]);
        r=max(r,pos[i]);
        if(r-l==i-1)printf("1");
        else printf("0");
    }
    puts("");
    return;
}
int main()
{
    int t;
    scanf("%d",&t);
    while (t--){
        int n;
        scanf("%d",&n);
        solve(n);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值