結果

問題 No.2771 Personal Space
コンテスト
ユーザー detteiuu
提出日時 2026-07-20 23:40:51
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 649 ms / 2,000 ms
+ 907µs
コード長 908 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 231 ms
コンパイル使用メモリ 96,364 KB
実行使用メモリ 128,452 KB
最終ジャッジ日時 2026-07-20 23:41:10
合計ジャッジ時間 15,629 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from sys import stdin
input = stdin.readline
from heapq import heappush, heappop

def cost(l, r):
    m = (l+r)//2
    return m-(l-1)

for _ in range(int(input())):
    N, M = map(int, input().split())

    que = []
    ans = [-1]*N
    ans[M-1] = 1
    if 2 <= M:
        heappush(que, (-(M-1), 0, M-2))
    if M < N:
        heappush(que, (-(N-M), M, N-1))
    for i in range(2, N+1):
        _, l, r = heappop(que)
        if l == 0:
            ans[l] = i
            if l+1 <= r:
                heappush(que, (-cost(l+1, r), l+1, r))
        elif r == N-1:
            ans[r] = i
            if l <= r-1:
                heappush(que, (-cost(l, r-1), l, r-1))
        else:
            m = (l+r)//2
            ans[m] = i
            if l <= m-1:
                heappush(que, (-cost(l, m-1), l, m-1))
            if m+1 <= r:
                heappush(que, (-cost(m+1, r), m+1, r))
    
    print(*ans)
0