RoAlgo PreOJI 2024 IX | sirpal

This was the problem page during the contest. Access the current page here.
Time limit: 0.3s Memory limit: 64MB Input: sirpal.in Output: sirpal.out

Task

LLM gives you a number nn and a sequence a1,a2,ana_1, a_2, \dots a_n of nn natural numbers. Now, he wants you to find for each position ii in the sequence if there exists a subsequence with the following properties:

  • Its length is greater than or equal to 33.
  • 1x1<x2<<xkn1 \leq x_1 < x_2 < \dots < x_k \leq n, where x1,x2,,xkx_1, x_2, \dots, x_k are positions from the initial sequence used for the found subsequence.
  • One of the chosen positions is ii and it is neither the first nor the last position in the subsequence (in other words, x1ix_1 \neq i and xkix_k \neq i).
  • If we consider the values at the kk positions, the sequence is a palindrome (for example, the sequence 7 14 14 77 \ 14 \ 14 \ 7 is a palindrome). A sequence s1 s2sqs_1 \ s_2 \dots s_q is a palindrome if and only if s1=sq,s2=sq1s_1 = s_q, s_2 = s_{q-1} and so on.

LLM quickly found the answers for each position in the sequence, now it's your turn to achieve what LLM has achieved.

Input data

The first line of the input file sirpal.in contains nn, the length of the sequence. The next line contains the nn values, representing the values in the sequence.

Output data

The first line of the output file sirpal.out will contain a binary sequence of length nn, where the value at position ii is 11 if we can find such a sequence that contains position ii and 00 otherwise. The values will be displayed without spaces.

Constraints and clarifications

  • 1n10000001 \leq n \leq 1\,000\,000
  • 1ai10000001 \leq a_i \leq 1\,000\,000 for each ii from 11 to nn
# Points Constraints
1 12 n3n \leq 3
2 16 n300n \leq 300
3 28 n2000n \leq 2\,000
4 44 No additional constraints

Example 1

sirpal.in

5
1 2 3 4 3

sirpal.out

00010

Explanation

We see that position 44 is the only one that satisfies the conditions. We can choose the subsequence formed by indices 3,4,53, 4, 5. We observe that it satisfies the conditions.

Example 2

sirpal.in

17
1 6 2 4 6 3 7 5 9 7 3 8 8 10 10 8 10

sirpal.out

00110011110011110

Explanation

For position 1414 (where the first 1010 is located) we can choose the subsequence 12,14,15,1612, 14, 15, 16. This is not the only option.

Log in or sign up to be able to send submissions!