結果

問題 No.1300 Sum of Inversions
ユーザー googol_S0googol_S0
提出日時 2020-11-27 21:33:50
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 796 ms / 2,000 ms
コード長 885 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 87,084 KB
実行使用メモリ 200,112 KB
最終ジャッジ日時 2023-10-01 04:58:54
合計ジャッジ時間 21,706 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,280 KB
testcase_01 AC 70 ms
71,164 KB
testcase_02 AC 70 ms
70,860 KB
testcase_03 AC 661 ms
153,936 KB
testcase_04 AC 595 ms
153,760 KB
testcase_05 AC 508 ms
123,284 KB
testcase_06 AC 681 ms
182,364 KB
testcase_07 AC 654 ms
162,468 KB
testcase_08 AC 726 ms
187,592 KB
testcase_09 AC 723 ms
187,460 KB
testcase_10 AC 429 ms
124,884 KB
testcase_11 AC 439 ms
124,680 KB
testcase_12 AC 603 ms
153,396 KB
testcase_13 AC 585 ms
153,040 KB
testcase_14 AC 796 ms
200,112 KB
testcase_15 AC 729 ms
187,280 KB
testcase_16 AC 638 ms
154,468 KB
testcase_17 AC 421 ms
120,012 KB
testcase_18 AC 474 ms
118,732 KB
testcase_19 AC 547 ms
136,296 KB
testcase_20 AC 562 ms
136,588 KB
testcase_21 AC 562 ms
137,052 KB
testcase_22 AC 510 ms
123,300 KB
testcase_23 AC 686 ms
182,292 KB
testcase_24 AC 520 ms
130,488 KB
testcase_25 AC 461 ms
118,184 KB
testcase_26 AC 442 ms
117,264 KB
testcase_27 AC 493 ms
123,248 KB
testcase_28 AC 768 ms
198,932 KB
testcase_29 AC 570 ms
136,712 KB
testcase_30 AC 745 ms
187,524 KB
testcase_31 AC 514 ms
130,308 KB
testcase_32 AC 536 ms
130,916 KB
testcase_33 AC 365 ms
134,828 KB
testcase_34 AC 387 ms
132,872 KB
testcase_35 AC 447 ms
177,624 KB
testcase_36 AC 532 ms
199,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Binit(B,siz):
  while len(B)<siz+1:
    B.append(0)
  while len(B)>siz+1:
    del B[-1]
  for i in range(siz+1):
    B[i]=0
  B.append(siz)

def Badd(B,a,x):
  z=a
  while z<=B[-1]:
    B[z]+=x
    z+=(z&(-z))

def Bsum(B,a):
  r=0
  z=a
  while z>0:
    r+=B[z]
    z-=(z&(-z))
  return r

def Bssum(B,a,b):
  return Bsum(B,max(a,b))-Bsum(B,min(a,b)-1)

BIT=[]
BC=[]
N=int(input())
A=list(map(int,input().split()))
Binit(BIT,N+1)
Binit(BC,N+1)
D=dict()
B=sorted(set(A))
for i in range(len(B)):
  D[B[i]]=i+1
C=[0]*N
Z=[0]*N
X=0
for i in range(N):
  C[i]=X-Bsum(BIT,D[A[i]])+(i-Bsum(BC,D[A[i]]))*A[i]
  X+=A[i]
  Z[i]=i-Bsum(BC,D[A[i]])
  Badd(BC,D[A[i]],1)
  Badd(BIT,D[A[i]],A[i])
X=0
P=0
Binit(BIT,N+1)
Binit(BC,N+1)
Y=0
for i in range(N):
  P+=X-Bsum(BIT,D[A[i]])+(Y-Bsum(BC,D[A[i]]))*A[i]
  X+=C[i]
  Y+=Z[i]
  Badd(BC,D[A[i]],Z[i])
  Badd(BIT,D[A[i]],C[i])
print(P%998244353)
0