private void solve() { int p = 0; int idx = 0; deck = new int[K]; tree = new BinaryTree(K + 1); for (int i = 0; i <= K; i++) tree.update(1, i + 1); for (int i = 0; i < K; i++) { p = p + i; p %= (K - i); idx = tree.binarySearch(p + 1); idx = adapt(idx); deck[idx] = i + 1; tree.update(-1, idx + 1); } for (int i = 0; i < cards.Length; i++) { cards[i] = deck[cards[i] - 1]; } }