UberOA #42
Get Balanced String
Estimated MediumJudge-ready
Topics (AI-labelled)In-place ArraysTwo Pointers
The array is a permutation of 1..n. For each k, determine whether some contiguous subarray contains exactly 1..k, each once, and output n values of 0/1 in order.
This site has made the standard input and output explicit.
Input
The first line contains n, and the second line contains the permutation; 1≤n≤100000.
Output
Output a 01 string of length n.
Example 1
Input:
4
4 1 3 2
Output:
1011
Example 2
Input:
3
1 2 3
Output:
111
Example 3
Input:
3
2 3 1
Output:
101
Example notes
Example 1: k=1, 3, 4 qualify; for k=2, 1 and 2 are separated by 3, so output 1011. Example 2: every prefix qualifies, so output 111. Example 3: 1 and 2 are not adjacent, so only k=1, 3 qualify; output 101.
Editorial
Loading solution…