#P4077. [SDOI2016] 硬币游戏

[SDOI2016] 硬币游戏

Description

Alice and Bob are playing a game with nn coins numbered from 11 to nn. Each coin has two sides, called heads and tails. Initially, some coins are heads up and some are tails up. Alice and Bob alternate performing flip operations on these coins, and Alice always moves first.

Specifically, on each turn, the player may choose an index xx such that the coin xx is currently tails up. For the index xx, we can always write x=c2a3bx = c \cdot 2^a \cdot 3^b, where aa and bb are non-negative integers, and cc is a non-negative integer that is coprime to both 22 and 33. Then there are two choices:

  • Choose integers p,qp, q satisfying apqa \ge pq, p1p \ge 1, and 1qMAXQ1 \leq q \leq \text{MAXQ}, then simultaneously flip all coins with indices c2apj3bc \cdot 2^{a - pj} \cdot 3^b, where j=0,1,2,,qj = 0, 1, 2, \ldots, q.

  • Choose integers p,qp, q satisfying bpqb \ge pq, p1p \ge 1, and 1qMAXQ1 \leq q \leq \text{MAXQ}, then simultaneously flip all coins with indices c2a3bpjc \cdot 2^a \cdot 3^{b - pj}, where j=0,1,2,,qj = 0, 1, 2, \ldots, q.

It can be seen that the game cannot continue indefinitely. When a player cannot make a move as described above, they lose the game. As the first player, Alice wants to know beforehand whether she can win. She assumes that both she and Bob are perfectly rational, so during the game both will optimize their strategies and try to avoid losing.

Input Format

There are multiple test cases. The first line contains an integer TT, the number of test cases. Then TT test cases follow.

For each test case, the first line contains two integers n,MAXQn, \text{MAXQ}.

The second line contains nn integers. The ii-th number denotes the initial state of the ii-th coin: 00 means tails up, and 11 means heads up.

Output Format

Output TT lines. For each test case, if Alice has a winning strategy as the first player, print win; otherwise print lose.

6
16 14
1 0 0 1 0 0 0 0 1 0 0 0 1 0 1 1
16 14
0 1 0 0 0 1 1 1 1 1 1 0 1 0 0 1
16 11
0 1 0 0 0 1 1 1 0 1 0 0 0 1 0 1
16 12
1 1 1 1 1 1 1 1 0 0 1 1 0 1 1 0
16 4
1 0 0 1 0 0 1 0 0 0 0 1 0 1 1 0
16 20
0 0 0 0 1 0 1 0 0 0 1 0 0 1 0 0
win
lose
win
lose
win
win

Hint

For 100%100\% of the testdata, 1n300001 \le n \le 30000, 1MAXQ201 \le \text{MAXQ} \le 20, T100T \le 100.

Translated by ChatGPT 5