← 返回 microsoft 的题目列表Balanced Prefix-Permutation Subarray for Every k
类型:online_judge
You are given a permutation p of length n (it contains each integer from 1 to n exactly once).
A number k is called balanced if there exist indices l, r (1 ≤ l ≤ r ≤ n) such that the subarray p[l..r] contains exactly the set {1,2,...,k} (equivalently, p[l..r] is a permutation of 1..k).
For each k from 1 to n, determine whether k is balanced. Return a binary string ans of length n where:
ans[k] = '1' if k is balanced
ans[k] = '0' otherwise
Note: since p is a permutation, for k to be balanced there must be a subarray of length k whose elements are exactly 1..k.
Input format (for implementation)
Line 1: integer n
Line 2: n integers representing p[1..n]
Output format
Output one binary string ans of length n.
Examples
Input:
5
1 2 3 4 5
Output:
11111
Input:
5
2 1 3 5 4
Output:
11101
Constraints
p is a permutation of 1..n
You must decide this for every k = 1..n.
Example
Input
5
1 2 3 4 5
Output
11111