题面
来源:USACO 官网。模型收到的是同一份题面的文字。
There is a line of cows, initially (i.e. at time $t = 0$) containing only cow $0$ at position $0$ (here, a cow is at position $k$ if there are $k$ cows in front of it). At time $t$ for $t=1,2,3,\dots$, the cow at position 0 moves to position $\lfloor t/2\rfloor$, every cow in positions $1\dots \lfloor t/2\rfloor$ moves forward one position, and cow $t$ joins the line at the end of the line (position $t$).
Answer $Q$ ($1\le Q\le 10^5$) independent queries, each of one of the following types:
- At what position is cow $c$ immediately after time $t$ ($0\le c\le t\le 10^{18}$)?
- Which cow is at position $x$ immediately after time $t$ ($0\le x\le t\le 10^{18}$)?
INPUT FORMAT (input arrives from the terminal / stdin):
The first line contains $Q$, the number of queries.The next $Q$ lines each contain three integers specifying a query either of the form "1 c t" or "2 x t."
OUTPUT FORMAT (print output to the terminal / stdout):
Output the answer to each query on a separate line.SAMPLE INPUT:
2 1 4 9 2 2 9
SAMPLE OUTPUT:
2 4
Lineups immediately after various times:
t = 0 | 0 t = 1 | 0 1 t = 2 | 1 0 2 t = 3 | 0 1 2 3 t = 4 | 1 2 0 3 4 t = 5 | 2 0 1 3 4 5 t = 6 | 0 1 3 2 4 5 6 t = 7 | 1 3 2 0 4 5 6 7 t = 8 | 3 2 0 4 1 5 6 7 8 t = 9 | 2 0 4 1 3 5 6 7 8 9
Immediately after $t=9$, the location of cow $4$ is $2$, and the cow located at position $2$ is $4$.
SAMPLE INPUT:
22 1 0 9 1 1 9 1 2 9 1 3 9 1 4 9 1 5 9 1 6 9 1 7 9 1 8 9 1 9 9 2 0 9 2 1 9 2 2 9 2 3 9 2 4 9 2 5 9 2 6 9 2 7 9 2 8 9 2 9 9 1 0 1000000000000000000 2 0 1000000000000000000
SAMPLE OUTPUT:
1 3 0 4 2 5 6 7 8 9 2 0 4 1 3 5 6 7 8 9 483992463350322770 148148148148148148
SCORING:
- Input 3: $Q\le 1000, t\le 100$
- Input 4: $t\le 5000$
- Inputs 5-8: All queries are of type 1.
- Inputs 9-12: All queries are of type 2.
Problem credits: Agastya Goel
结果
Kimi K3.1 ProKimi
1/1
解出的采样 ↑
- 100采样 1 · 解出
- 11.1k平均输出 token(含思考) ↓
- 28.3输出速度 tokens/s ↑
- 394 秒延迟 ↓
- 0.50×CPU 时间 / 官方解 ↓
- 同阶时间复杂度(相对官方解)
- 4Pylint 问题 ↓
- 9.09Pylint 得分 ↑
- 14圈复杂度 ↓
- 54.9可维护性指数 ↑
DeepSeek Flash V4.1-1017DeepSeek
1/1
解出的采样 ↑
- 100采样 1 · 解出
- 21.5k平均输出 token(含思考) ↓
- 226.3输出速度 tokens/s ↑
- 96 秒延迟 ↓
- 0.45×CPU 时间 / 官方解 ↓
- 不可测时间复杂度(相对官方解)
- 4Pylint 问题 ↓
- 9.05Pylint 得分 ↑
- 12圈复杂度 ↓
- 53.1可维护性指数 ↑
MiniMax M3.1 FlashMiniMax
1/1
解出的采样 ↑
- 100采样 1 · 解出
- 151.5k平均输出 token(含思考) ↓
- 467.9输出速度 tokens/s ↑
- 324 秒延迟 ↓
- 0.30×CPU 时间 / 官方解 ↓
- 更优时间复杂度(相对官方解)
- 5Pylint 问题 ↓
- 8.96Pylint 得分 ↑
- 15圈复杂度 ↓
- 58.1可维护性指数 ↑
↑ 越大越好,↓ 越小越好。得分 0–100,按官方时限判定,所有测试点都满分才算解出。CPU 时间 / 官方解为解出的答案在官方解最慢的 3 个测试点上的 CPU 时间之比(几何平均),只比较官方解至少需要 0.05 秒的题;复杂度按增长幂次相对官方解分类。判题与计分见 原理。
代码
import sys def cow_position(c, t): if c == 0: front = 0 else: first_front = 3 * c - 1 if t < first_front: if t < 2 * c: return c return first_front - t front = first_front while front < t: next_front = (3 * (front + 1)) // 2 if next_front > t: return next_front - t front = next_front return 0 def cow_at_position(x, t): if x > t // 2: return x # This cow is (or will be) at the front at time front_time. front_time = t + x while front_time: r = front_time % 3 if r == 2: # First time at the front for cow c: time = 3*c - 1. return (front_time + 1) // 3 if r == 0: front_time = 2 * (front_time // 3) - 1 else: front_time = 2 * ((front_time - 1) // 3) return 0 def main(): data = list(map(int, sys.stdin.buffer.read().split())) q = data[0] answers = [] idx = 1 for _ in range(q): query_type = data[idx] value = data[idx + 1] t = data[idx + 2] idx += 3 if query_type == 1: answers.append(str(cow_position(value, t))) else: answers.append(str(cow_at_position(value, t))) sys.stdout.write("\n".join(answers)) if __name__ == "__main__": main()
import sys def cow_position(c, t): if c == 0: z = 0 else: if t < 2 * c: return c z = 3 * c - 1 while z < t: z += 1 + ((z + 1) // 2) return z - t def cow_at_position(x, t): s = t i = x while True: if s == 0: return 0 k = s // 2 if i > k: return i if i == k: i = 0 s -= 1 continue # i < k: jump through consecutive backward moves steps = (s - 2 * i - 2) // 3 + 1 s -= steps i += steps def main(): data = list(map(int, sys.stdin.buffer.read().split())) q = data[0] idx = 1 out = [] for _ in range(q): typ = data[idx] a = data[idx + 1] t = data[idx + 2] idx += 3 if typ == 1: out.append(str(cow_position(a, t))) else: out.append(str(cow_at_position(a, t))) sys.stdout.write("\n".join(out)) if __name__ == "__main__": main()
import sys TABLE_LIMIT = 1 << 16 _table = None def _build_table(): global _table tab = [0] * TABLE_LIMIT for y in range(1, TABLE_LIMIT): if y % 3 == 1: tab[y] = (y - 1) // 3 else: tab[y] = tab[(y + y) // 3] _table = tab def solve(): global _table data = sys.stdin.buffer.read().split() if not data: return q = int(data[0]) out = [] add = out.append i = 1 for _ in range(q): typ = data[i] a = int(data[i + 1]) t = int(data[i + 2]) i += 3 half = t >> 1 if typ == b'1': # position of cow a at time t if a > half: add(str(a)) else: v = 3 * a + 2 if a else 3 # V = first_front_time + 3 lim = t + 3 while v < lim: v += v >> 1 # v <- floor(3v/2) add(str(v - 3 - t)) else: # cow at position a at time t if a > half: add(str(a)) else: if _table is None: _build_table() y = a + t + 2 while y >= TABLE_LIMIT and y % 3 != 1: y = (y + y) // 3 # y <- floor(2y/3) if y % 3 == 1: add(str((y - 1) // 3)) else: add(str(_table[y])) sys.stdout.write('\n'.join(out)) sys.stdout.write('\n') if __name__ == "__main__": solve()