UberOA #18
Balanced Prefix Sets in a Permutation
Estimated MediumJudge-ready
Topics (AI-labelled)In-place ArraysTwo Pointers
For each k, given a permutation of 1..n, determine whether some contiguous subarray has a value set of exactly {1..k}, and output the results in order as an n-character 01 string.
This site's standard input/output is stated explicitly.
Input
The first line contains n, and the second line contains a permutation of 1..n. This site's range is 1≤n≤100000.
Output
Output a 01 string of length n, where the k-th character indicates whether some contiguous subarray has value set {1..k}.
Example 1
Input:
4
2 1 4 3
Output:
1101
Example 2
Input:
5
3 1 2 5 4
Output:
11101
Example 3
Input:
1
1
Output:
1
Example notes
Example 1: the positions are contiguous for k equal to 1, 2, and 4, so the output is 1101. Example 2: they are contiguous for k equal to 1, 2, 3, and 5, so the output is 11101. Example 3: the only element forms the set {1} by itself, so the output is 1.
Editorial
Loading solution…