結果

問題 No.2665 Minimize Inversions of Deque
ユーザー 👑 p-adicp-adic
提出日時 2023-12-30 10:10:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 362 ms / 2,000 ms
コード長 399 bytes
コンパイル時間 155 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 107,248 KB
最終ジャッジ日時 2024-01-05 15:03:12
合計ジャッジ時間 10,335 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,460 KB
testcase_01 AC 303 ms
77,336 KB
testcase_02 AC 362 ms
78,460 KB
testcase_03 AC 267 ms
76,960 KB
testcase_04 AC 258 ms
76,960 KB
testcase_05 AC 261 ms
76,576 KB
testcase_06 AC 261 ms
76,828 KB
testcase_07 AC 267 ms
77,472 KB
testcase_08 AC 255 ms
76,572 KB
testcase_09 AC 250 ms
76,576 KB
testcase_10 AC 261 ms
76,704 KB
testcase_11 AC 255 ms
76,572 KB
testcase_12 AC 251 ms
76,828 KB
testcase_13 AC 255 ms
76,844 KB
testcase_14 AC 255 ms
76,572 KB
testcase_15 AC 277 ms
76,832 KB
testcase_16 AC 260 ms
76,580 KB
testcase_17 AC 280 ms
76,956 KB
testcase_18 AC 275 ms
76,832 KB
testcase_19 AC 180 ms
77,440 KB
testcase_20 AC 78 ms
76,208 KB
testcase_21 AC 77 ms
76,352 KB
testcase_22 AC 63 ms
74,420 KB
testcase_23 AC 68 ms
76,164 KB
testcase_24 AC 75 ms
76,160 KB
testcase_25 AC 70 ms
75,900 KB
testcase_26 AC 85 ms
76,348 KB
testcase_27 AC 78 ms
76,172 KB
testcase_28 AC 69 ms
76,024 KB
testcase_29 AC 71 ms
76,020 KB
testcase_30 AC 224 ms
104,036 KB
testcase_31 AC 185 ms
89,984 KB
testcase_32 AC 194 ms
95,416 KB
testcase_33 AC 205 ms
99,784 KB
testcase_34 AC 185 ms
90,164 KB
testcase_35 AC 181 ms
107,248 KB
testcase_36 AC 181 ms
107,248 KB
testcase_37 AC 195 ms
89,228 KB
testcase_38 AC 198 ms
97,248 KB
testcase_39 AC 218 ms
107,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

I,O,R=input,print,range
def A(i,t):
	i+=1
	while i<=N:F[i],i=F[i]+t,i+(i&-i)
def L(r):
	a=0
	i=min(r+1,N)
	while i:a,i=a+F[i],i-(i&-i)
	return a
for t in R(int(I())):
	N,a,X,Y=int(I()),0,[],[]
	P,F=list(map(int,I().split())),[0]*(N+1)
	for i,p in zip(R(N),P):
		c=L(p)
		if c<i-c or not(X or Y)or(i==2*c and X[-1]>p):
			a+=c
			X+=[p]
		else:
			a+=i-c
			Y+=[p]
		A(p,1)
	X.reverse(),O(a),O(*X,*Y)
0