#P11565. 【MX-X7-T6】[LSOT-3] 棋盘

    ID: 11736 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP博弈论O2优化Ad-hoc分类讨论梦熊比赛

【MX-X7-T6】[LSOT-3] 棋盘

Background

Original link: https://oier.team/problems/X7G.

There is now a sequence.

The 11st term of this sequence is 00, the 22nd term is 11, the 33rd term is 11, and the 44th term is 33.

Now @lxwtr asks you what the value of the nn-th term is.

Problem Description

Alice and Bob found a chessboard. The chessboard can be viewed as a number line. Initially, there are nn pieces at the origin. Let aia_i denote the number of pieces at position ii on the number line (the origin is i=0i=0). Each time, the player finds the smallest ii such that ai2a_i\ge 2, decreases aia_i by 22, and then chooses either to increase ai+1a_{i+1} by 11 or to increase ai+2a_{i+2} by 11. Alice moves first, and they take turns operating. A player must make a move; if no such ii can be found, the game ends immediately.

Alice wants the total number of moves made by both players to be as small as possible, while Bob wants the total number of moves made by both players to be as large as possible. Both players are perfectly smart. They played TT games in total, and you want to know, for each game, how many moves in total will be made in the end.

Input Format

The first line contains a positive integer TT, representing the number of games played.

The next TT lines each contain a positive integer nn, representing the number of pieces at the origin at the start of each game.

Output Format

Output TT lines. The ii-th line contains a non-negative integer, representing the total number of moves made by both players in the ii-th game.

6
1
2
3
4
100
100000

0
1
1
3
95
99989

Hint

Sample Explanation

For the first game, the number of pieces at the origin is 11, so no move can be made.

For the second game, exactly one move can be made, after which a1=1a_1=1 or a2=1a_2=1. Either way, no further move can be made.

For the third game, it is similar to the second game, except that one extra piece is left at the origin.

For the fourth game, no matter where Alice places the piece after the first move, Bob can place it at the same position, so Alice will make one more move. There are 33 moves in total.

Constraints

This problem uses bundled testdata.

  • Subtask 1 (5 points): n16n\le16.
  • Subtask 2 (6 points): n50n\le 50.
  • Subtask 3 (14 points): n200n\le 200.
  • Subtask 4 (20 points): n5000n\le 5000.
  • Subtask 5 (21 points): n105n\le 10^5.
  • Subtask 6 (34 points): no special properties.

For all testdata, 1T5001\le T\le 500, 1n10181\le n\le 10^{18}.

Translated by ChatGPT 5