← 返回 uber 的题目列表Balanced Prefix Set in a Permutation
类型:online_judge
You are given a permutation p of length n (it contains each integer 1..n exactly once).
For each k (1 <= k <= n), call k balanced if there exists a contiguous subarray p[l..r] such that the set of elements in that subarray is exactly {1,2,...,k} (in any order).
For every k, determine whether it is balanced and return a binary string (or 0/1 array) ans of length n:
ans[k] = '1' if k is balanced
ans[k] = '0' otherwise
Input format
Line 1: integer n
Line 2: n integers, the permutation p[1..n]
Output format
A binary string ans of length n for k=1..n.
Constraints
1 <= n <= 2*10^5
p is a permutation of 1..n
Sample tests (stdin/stdout)
input
5
1 3 2 4 5
output
11111
input
5
2 1 4 3 5
output
10101
input
5
3 1 2 5 4
output
01101
input
1
1
output
1
input
6
4 1 3 2 6 5
output
011011
Example
Input
5
1 3 2 4 5
Output
11111