来源: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. SQL Server 2008创建数据库

    1.数据.数据库.数据管理系统基本概念: 数据:人类有用信息的符号化表示. 数据库:按照数据结构来组织.存储和管理数据的一个仓库. 数据库管理系统(DBMS):可维护.存储并为应用系统提供数据的软件系 ...

  2. C++-怎样写程序(面向对象)

    使用编程语言写好程序是有技巧的. 主要编程技术: 1. 编程风格 2. 算法 3. 数据结构 4. 设计模式 5. 开发方法 编程风格指的是编程的细节,比如变量名的选择方法.函数的写法等. 算法是解决 ...

  3. matplotlib 做图通过弹出窗口展示 spyder

    tools =>preferences=>Ipython console=>Graphics Graphics backend 中Backend 由Inline改为 Automati ...

  4. 第k个数(排序)

    给定一个长度为n的整数数列,以及一个整数k,请用快速选择算法求出数列的第k小的数是多少. 输入格式 第一行包含两个整数 n 和 k. 第二行包含 n 个整数(所有整数均在1~109109范围内),表示 ...

  5. layui表单之单选框提交

    <div class="layui-form-item"> <label class="layui-form-label">状态< ...

  6. Java-POJ1014-Dividing

    多重背包问题的特点是物品数量可以大于1但是有限制.状态定义与01背包一致. 多重背包的解法有多种,复杂度也各不相同. 对于物品数Ci较大的数据,可以采取二进制数进行优化(就是这样,别问就是baidu! ...

  7. Array,String,Set,Map

    热爱前端的17号诶 积跬步以致千里 积怠惰以致深渊 博客园 首页 新随笔 联系 管理 随笔 - 58  文章 - 2  评论 - 65 最新数组方法(包括es6) for...of 是 ES6 新引入 ...

  8. Spark 中 GroupByKey 相对于 combineByKey, reduceByKey, foldByKey 的优缺点

    避免使用GroupByKey 我们看一下两种计算word counts 的方法,一个使用reduceByKey,另一个使用 groupByKey: val words = Array("on ...

  9. update_jz首项V5.0-Tutorial

    What's New: 增加了4个对话框,用于展示信息.归并条目.剔除条目 增加了可视化统计图形中每个科室(柱形)的统计总数 可视化图形一些颜色调整(无奈在省份很多的条件下一些颜色还不易区分) 下面是 ...

  10. 【Python】蟒蛇绘制

    来画一只你的小蛇吧! 1. 2. 3.了解turtle库 Turtle,也叫海龟渲染器,使用Turtle库画图也叫海龟作图.Turtle库是Python语言中一个很流行的绘制图像的函数库.海龟渲染器, ...