#P10014. [集训队互测 2023] 茧

[集训队互测 2023] 茧

Problem Description

Lily is an interesting girl. She often plays some strange games with Kaguya.

Today they are playing a game called nim. Specifically, the rules of nim are as follows:

  • There are several piles of a known number of stones. Two players take turns removing any positive number of stones from any one pile.
  • Lily moves first. The player who cannot make a move loses, i.e. the one who removes the last stone wins.

Because the optimal strategy is very simple, after a few rounds they started to feel bored. So, based on the original rules, they added one more rule:

  • From a pile with xx stones, you can remove yy stones if and only if ykxy^k \le x.

Now the game becomes interesting. However, since the strategy is rather complicated, Lily often finds it hard to compute.

It can be proven that for any position of this game, either Lily has a winning strategy, or Kaguya has a winning strategy.

So Lily wants you to write a program to determine who has a winning strategy in a given position (Lily always moves first), so that she can analyze which move was a mistake when reviewing the game.

Since the curious Lily may analyze positions in detail, you need to answer multiple queries.

Because all positions come from reviewing the same game, the parameter kk is the same for all queries.

The queried positions have a special form. See the input format for details.

Input Format

The first line contains two integers t,kt, k, representing the number of queries and the parameter in the move rule.

Then follow the queries. For each query:

The first line contains an integer nn.

The second line contains nn integers a1,,ana_1, \dots, a_n.

(n,a1n)(n, a_{1 \dots n}) means there are ai\sum a_i piles of stones, and the numbers of stones in each pile are respectively 1a1,1a2,,1an1 \dots a_1, 1 \dots a_2, \dots, 1 \dots a_n.

If you are familiar with game theory, it is not hard to see that the problem can be transformed into:

  • Let the Grundy value of a pile with xx stones be g(x)g(x), and let h(x)h(x) be the prefix xor sum of g(x)g(x). Determine whether the xor of h(a1)h(an)h(a_1) \dots h(a_n) is 00.

Output Format

For each query, output one string per line.

  • If Lily has a winning strategy, output Lily.
  • If Kaguya has a winning strategy, output Kaguya.
3 1
2
1 5
3
1 2 3
1
3

Kaguya
Lily
Kaguya

4 2
2
1 2
2
1 3
3
5 6 7
1
3

Kaguya
Lily
Kaguya
Kaguya

Hint

For samples 3, 4, and 5, see the attached file.

For all testdata, it is guaranteed that 1k51 \le k \le 5, 1n,n1051 \le n, \sum n \le 10^5, and 1ai<2601 \le a_i \lt 2^{60}.

The detailed limits for each subtask are shown in the table below:

Subtask ID nn kk aia_i Special Property Score
1 n105\sum n \le 10^5 k=1k = 1 ai<260a_i < 2^{60} 55
2 2k52 \le k \le 5 ai<216a_i < 2^{16}
3 ai<222a_i < 2^{22} 1010
4 n103\sum n \le 10^3, n=2n = 2 2k32 \le k \le 3 ai<232a_i < 2^{32} A
5 n103\sum n \le 10^3 2k52 \le k \le 5
6 n105\sum n \le 10^5 k=2k = 2 ai<260a_i < 2^{60}
7 k=3k = 3
8 n103\sum n \le 10^3 k=2k = 2 ai<232a_i < 2^{32}
9 k=3k = 3
10 n105\sum n \le 10^5 1k51 \le k \le 5 ai<260a_i < 2^{60} 2020

Special property A: it is guaranteed that 2n2 \mid n, and $a_{2k - 1} = a_{2k} - 1 \pod{1 \le k \le \frac n 2}$.

Hint: If you get an unexpected TLE, you may try to optimize your time complexity.

Slightly adjusted a few wordings in the statement.

Please refer to QOJ for the original statement.

Translated by ChatGPT 5