COCI '25 Contest 1 #5 Zagi

View as PDF

Submit solution

Points: 20 (partial)
Time limit: 3.0s
Memory limit: 512M

Problem types

Jakov and Toni, the two best players in the world, will face each other in the finals of the world championship in krastoboj.

Krastoboj is a game played by two players on a sequence of positive integers. The players take turns making moves, and the player who cannot make a move loses the game. At the very beginning, there is only one sequence of positive integers on the board - the initial sequence.

In one move, a player chooses one of the existing sequences and one number x that appears in that sequence. Then they delete all occurrences of x in the chosen sequence, thereby splitting the sequence into several new sequences separated at the positions where x appeared.

A sequence of numbers - the template for the final match - has been found. It is known that the initial sequence in the final will be some contiguous subsequence of this template sequence. You are given q scenarios. For each scenario, can you determine who the winner will be, assuming that both Toni and Jakov play optimally and that Toni makes the first move?

Input Specification

The first line contains two positive integers n and q (1 \le n, q \le 10^5).

The second line contains a sequence of positive integers a_1, a_2, \dots, a_n (1 \le a_i \le 32 for each i = 1, 2, \dots, n).

The following q lines each contain two integers l_i and r_i (1 \le l_i \le r_i \le n), the boundaries of the contiguous subsequence considered in the i-th scenario.

Output Specification

For each query, print on a separate line either Toni or Jakov, the name of the winner in the i-th scenario.

Constraints

Subtask Points Constraints
1 15 n, q \le 10
2 11 n, q \le 1\,000, a_i \le 2
3 18 n, q \le 1\,000
4 14 a_i \le 2
5 23 a_{l_i} = a_{r_i} for every i = 1, \dots, q
6 29 No additional constraints.

Sample Input 1

6 4
1 3 2 3 1 2
1 1
2 3
2 4
1 3

Sample Output 1

Toni
Jakov
Toni
Toni

Explanation for Sample Output 1

In the third scenario, Toni chooses x = 2, which splits the sequence into two sequences of length 1. Whichever sequence Jakov chooses next, Toni will choose the remaining one, after which Jakov will have no possible moves left.

Sample Input 2

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

Sample Output 2

Toni
Jakov
Toni
Toni
Toni

Comments

There are no comments at the moment.