結果
問題 | No.2771 Personal Space |
ユーザー | PNJ |
提出日時 | 2024-05-31 22:15:40 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,395 bytes |
コンパイル時間 | 313 ms |
コンパイル使用メモリ | 82,300 KB |
実行使用メモリ | 137,024 KB |
最終ジャッジ日時 | 2024-05-31 22:16:22 |
合計ジャッジ時間 | 41,884 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
54,544 KB |
testcase_01 | AC | 1,338 ms
131,784 KB |
testcase_02 | AC | 1,391 ms
132,364 KB |
testcase_03 | AC | 1,313 ms
131,696 KB |
testcase_04 | AC | 1,325 ms
131,900 KB |
testcase_05 | AC | 1,357 ms
133,516 KB |
testcase_06 | AC | 1,326 ms
132,376 KB |
testcase_07 | AC | 1,415 ms
89,748 KB |
testcase_08 | AC | 981 ms
78,768 KB |
testcase_09 | AC | 1,328 ms
92,248 KB |
testcase_10 | AC | 1,945 ms
128,536 KB |
testcase_11 | AC | 1,712 ms
130,772 KB |
testcase_12 | AC | 1,811 ms
125,892 KB |
testcase_13 | TLE | - |
testcase_14 | AC | 1,748 ms
97,732 KB |
testcase_15 | AC | 1,655 ms
113,548 KB |
testcase_16 | AC | 1,618 ms
112,812 KB |
testcase_17 | AC | 1,689 ms
117,260 KB |
testcase_18 | AC | 1,754 ms
96,224 KB |
testcase_19 | AC | 1,825 ms
95,844 KB |
testcase_20 | AC | 1,658 ms
130,968 KB |
testcase_21 | AC | 1,663 ms
127,880 KB |
testcase_22 | AC | 1,614 ms
127,008 KB |
testcase_23 | AC | 1,589 ms
137,024 KB |
testcase_24 | AC | 1,537 ms
125,596 KB |
ソースコード
import heapq class segtree(): n=1 size=1 log=2 d=[0] op=None e=10**15 def __init__(self,V,OP,E): self.n=len(V) self.op=OP self.e=E self.log=(self.n-1).bit_length() self.size=1<<self.log self.d=[E for i in range(2*self.size)] for i in range(self.n): self.d[self.size+i]=V[i] for i in range(self.size-1,0,-1): self.update(i) def set(self,p,x): assert 0<=p and p<self.n p+=self.size self.d[p]=x for i in range(1,self.log+1): self.update(p>>i) def get(self,p): assert 0<=p and p<self.n return self.d[p+self.size] def prod(self,l,r): assert 0<=l and l<=r and r<=self.n sml=self.e smr=self.e l+=self.size r+=self.size while(l<r): if (l&1): sml=self.op(sml,self.d[l]) l+=1 if (r&1): smr=self.op(self.d[r-1],smr) r-=1 l>>=1 r>>=1 return self.op(sml,smr) def all_prod(self): return self.d[1] def max_right(self,l,f): assert 0<=l and l<=self.n assert f(self.e) if l==self.n: return self.n l+=self.size sm=self.e while(1): while(l%2==0): l>>=1 if not(f(self.op(sm,self.d[l]))): while(l<self.size): l=2*l if f(self.op(sm,self.d[l])): sm=self.op(sm,self.d[l]) l+=1 return l-self.size sm=self.op(sm,self.d[l]) l+=1 if (l&-l)==l: break return self.n def min_left(self,r,f): assert 0<=r and r<=self.n assert f(self.e) if r==0: return 0 r+=self.size sm=self.e while(1): r-=1 while(r>1 and (r%2)): r>>=1 if not(f(self.op(self.d[r],sm))): while(r<self.size): r=(2*r+1) if f(self.op(self.d[r],sm)): sm=self.op(self.d[r],sm) r-=1 return r+1-self.size sm=self.op(self.d[r],sm) if (r& -r)==r: break return 0 def update(self,k): self.d[k]=self.op(self.d[2*k],self.d[2*k+1]) def __str__(self): return str([self.get(i) for i in range(self.n)]) inf = 1 << 60 def solve(): N,M = map(int,input().split()) segmax = segtree([0 for i in range(N+1)],max,0) segmin = segtree([inf for i in range(N+1)],min,inf) segmax.set(M,M) segmin.set(M,M) H = [] heapq.heappush(H,(-(M-1),1)) heapq.heappush(H,(-(N-M),N)) ans = [-1 for i in range(N)] ans[0] = M for i in range(1,N): d,u = heapq.heappop(H) ans[i] = u if u > 1: v = segmax.prod(0,u) if v != u - 1: m = (u + v) // 2 heapq.heappush(H,(-(m-v),m)) if u < N: v = segmin.prod(u+1,N+1) if v != u + 1: m = (u + v) // 2 heapq.heappush(H,(-(m-u),m)) segmax.set(u,u) segmin.set(u,u) P = [0 for i in range(N)] for i in range(N): q = ans[i] P[q-1] = i + 1 print(*P) return for _ in range(int(input())): solve()