来源:http://codeforces.com/problemset/problem/1265/B
 
B. Beautiful Numbers
 

You are given a permutation p=[p1,p2,…,pn]p=[p1,p2,…,pn] of integers from 11 to nn . Let's call the number mm (1≤m≤n1≤m≤n ) beautiful, if there exists two indices l,rl,r (1≤l≤r≤n1≤l≤r≤n ), such that the numbers [pl,pl+1,…,pr][pl,pl+1,…,pr] is a permutation of numbers 1,2,…,m1,2,…,m .

For example, let p=[4,5,1,3,2,6]p=[4,5,1,3,2,6] . In this case, the numbers 1,3,5,61,3,5,6 are beautiful and 2,42,4 are not. It is because:

  • if l=3l=3 and r=3r=3 we will have a permutation [1][1] for m=1m=1 ;
  • if l=3l=3 and r=5r=5 we will have a permutation [1,3,2][1,3,2] for m=3m=3 ;
  • if l=1l=1 and r=5r=5 we will have a permutation [4,5,1,3,2][4,5,1,3,2] for m=5m=5 ;
  • if l=1l=1 and r=6r=6 we will have a permutation [4,5,1,3,2,6][4,5,1,3,2,6] for m=6m=6 ;
  • it is impossible to take some ll and rr , such that [pl,pl+1,…,pr][pl,pl+1,…,pr] is a permutation of numbers 1,2,…,m1,2,…,m for m=2m=2 and for m=4m=4 .

You are given a permutation p=[p1,p2,…,pn]p=[p1,p2,…,pn] . For all mm (1≤m≤n1≤m≤n ) determine if it is a beautiful number or not.

Input

The first line contains the only integer tt (1≤t≤10001≤t≤1000 )  — the number of test cases in the input. The next lines contain the description of test cases.

The first line of a test case contains a number nn (1≤n≤2⋅1051≤n≤2⋅105 ) — the length of the given permutation pp . The next line contains nn integers p1,p2,…,pnp1,p2,…,pn (1≤pi≤n1≤pi≤n , all pipi are different) — the given permutation pp .

It is guaranteed, that the sum of nn from all test cases in the input doesn't exceed 2⋅1052⋅105 .

Output

Print tt lines — the answers to test cases in the order they are given in the input.

The answer to a test case is the string of length nn , there the ii -th character is equal to 11 if ii is a beautiful number and is equal to 00 if ii is not a beautiful number.

Example
Input

Copy
3
6
4 5 1 3 2 6
5
5 3 1 2 4
4
1 4 3 2
Output

Copy
101011
11111
1001
Note

The first test case is described in the problem statement.

In the second test case all numbers from 11 to 55 are beautiful:

  • if l=3l=3 and r=3r=3 we will have a permutation [1][1] for m=1m=1 ;
  • if l=3l=3 and r=4r=4 we will have a permutation [1,2][1,2] for m=2m=2 ;
  • if l=2l=2 and r=4r=4 we will have a permutation [3,1,2][3,1,2] for m=3m=3 ;
  • if l=2l=2 and r=5r=5 we will have a permutation [3,1,2,4][3,1,2,4] for m=4m=4 ;
  • if l=1l=1 and r=5r=5 we will have a permutation [5,3,1,2,4][5,3,1,2,4] for m=5m=5 .

 解题思路:记录每个值的位置,从1开始让最小的区间包围1-i,如果区间长度正好等于i就说明是一个i的排列。

#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
inline int read() {int x=,f=;char c=getchar();while(c!='-'&&(c<''||c>''))c=getchar();if(c=='-')f=-,c=getchar();while(c>=''&&c<='')x=x*+c-'',c=getchar();return f*x;}
typedef unsigned long long ll;
const int maxn = 1e6+;
int a[maxn];
int main()
{
int t;
cin>>t;
while(t--){
int n;
cin>>n;
int k;
for(int i=;i<=n;i++){
cin>>k;
a[k]=i;
}
int l,r;
l=r=a[];
cout<<;
for(int i=;i<=n;i++){
l=min(l,a[i]);
r=max(r,a[i]);
if(r-l+==i){
cout<<;
}
else{
cout<<;
}
}
cout<<endl;
}
return ;
}

codeforces Beautiful Numbers的更多相关文章

  1. [codeforces 55]D. Beautiful numbers

    [codeforces 55]D. Beautiful numbers 试题描述 Volodya is an odd boy and his taste is strange as well. It ...

  2. codeforces 55D - Beautiful numbers(数位DP+离散化)

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  3. Codeforces Round #181 (Div. 2) C. Beautiful Numbers 排列组合 暴力

    C. Beautiful Numbers 题目连接: http://www.codeforces.com/contest/300/problem/C Description Vitaly is a v ...

  4. Codeforces Beta Round #51 D. Beautiful numbers 数位dp

    D. Beautiful numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/p ...

  5. CodeForces 55D "Beautiful numbers"(数位DP+离散化处理)

    传送门 参考资料: [1]:CodeForces 55D Beautiful numbers(数位dp&&离散化) 我的理解: 起初,我先定义一个三维数组 dp[ i ][ j ][ ...

  6. Codeforces 55D. Beautiful numbers(数位DP,离散化)

    Codeforces 55D. Beautiful numbers 题意 求[L,R]区间内有多少个数满足:该数能被其每一位数字都整除(如12,24,15等). 思路 一开始以为是数位DP的水题,觉得 ...

  7. CodeForces 55D Beautiful numbers

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  8. Codeforces Beta Round #51 D. Beautiful numbers

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  9. CodeForces - 55D Beautiful numbers —— 数位DP

    题目链接:https://vjudge.net/problem/CodeForces-55D D. Beautiful numbers time limit per test 4 seconds me ...

随机推荐

  1. 百度地图和echarts结合实例

    1.由echart对象(bmapChart)获取百度地图对象(bdMap),echart对象(bmapChart)适用于所有的echart的操作和接口,百度地图对象(bdMap)适用于百度地图的所有接 ...

  2. java json转换工具类

    在java项目中,通常会用到json类型的转换,常常需要对 json字符串和对象进行相互转换. 在制作自定义的json转换类之前,先引入以下依赖 <!--json相关工具--><de ...

  3. 215. 数组中的第K个最大元素(TOP-K问题)

    问题: 在未排序的数组中找到第 k 个最大的元素.请注意,你需要找的是数组排序后的第 k 个最大的元素,而不是第 k 个不同的元素. 示例 1: 输入: [3,2,1,5,6,4] 和 k = 2输出 ...

  4. win7系统Java 开发环境配置

    我的天啊,博客园写了两年九个月,终于有六个粉丝啦,哈哈哈哈哈哈哈哈哈,谢谢大家的关注 进入正题,java环境配置,我要学java了,人生在于瞎折腾. 久闻java大名,但是没接触过,但java环境配置 ...

  5. 解决linux 中文乱码

    解决办法是在文件/etc/profile末尾添加一行 echo 'export LC_ALL="en_US.UTF-8"' >> /etc/profile source ...

  6. ABB工业机器人(条件执行数字信号判断,画方or画圆)

    一.前戏 条件:从安全点,到工具区域夹取工具(笔),到工作区域,判断数字信号 Di1 =1 ,Ture :画方,False:画圆,回到工具区域放下工具(笔),回到安全点 二. 准备工作 校准tcp工具 ...

  7. CentOS7 卸载Firefox

    先进入管理员模式 执行: yum remove firefox 然后用whereis 查看,却发现还是有: [root@localhost ~]# whereis firefox firefox: / ...

  8. Educational Codeforces Round 76 (Rated for Div. 2) B. Magic Stick

    Recently Petya walked in the forest and found a magic stick. Since Petya really likes numbers, the f ...

  9. [lua]紫猫lua教程-命令宝典-L1-01-01. Lua环境与IDE

    网上大把的lua教程  不过紫猫老师的教程向来都是讲的非常仔细 所以最近天气已经36+了 魔兽世界还需要冲飞行声望  懒得写单子根本没有单子,正好认认真真的看下紫猫老师的lua教程 紫猫老师的lua教 ...

  10. linux shell 正则表达式详解

    正则 1. 普通正则表达式 2. 扩展正则表达式 普通正则表达式 . 任意一个字符 * 前面一个字符出现0次或者多次 [abc] 中括号内任意一个字符 [^abc] 非括号内任意一个字符 [0-9] ...