#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 stones, you can remove stones if and only if .
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 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 , 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 .
The second line contains integers .
means there are piles of stones, and the numbers of stones in each pile are respectively .
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 stones be , and let be the prefix xor sum of . Determine whether the xor of is .
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 , , and .
The detailed limits for each subtask are shown in the table below:
| Subtask ID | Special Property | Score | |||
|---|---|---|---|---|---|
| 1 | |||||
| 2 | |||||
| 3 | |||||
| 4 | , | A | |||
| 5 | |||||
| 6 | |||||
| 7 | |||||
| 8 | |||||
| 9 | |||||
| 10 |
Special property A: it is guaranteed that , 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