結果

問題 No.2616 中央番目の中央値
ユーザー ゼットゼット
提出日時 2024-01-26 23:19:22
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,152 bytes
コンパイル時間 173 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 156,964 KB
最終ジャッジ日時 2024-01-26 23:19:29
合計ジャッジ時間 6,703 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 40 ms
53,460 KB
testcase_03 AC 37 ms
53,460 KB
testcase_04 AC 38 ms
53,460 KB
testcase_05 AC 38 ms
53,460 KB
testcase_06 AC 38 ms
53,460 KB
testcase_07 AC 38 ms
53,460 KB
testcase_08 AC 42 ms
59,724 KB
testcase_09 AC 44 ms
59,724 KB
testcase_10 AC 56 ms
66,252 KB
testcase_11 AC 68 ms
70,380 KB
testcase_12 AC 91 ms
76,064 KB
testcase_13 AC 412 ms
82,496 KB
testcase_14 AC 1,278 ms
93,840 KB
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

class segtree:
  def __init__(self,n):
    self.size=1
    while self.size<n:
      self.size*=2
    self.dat=[0]*(self.size*2)
  def update(self,x,a):
    x+=self.size
    self.dat[x]=a
    while x>1:
      x//=2
      self.dat[x]=(self.dat[2*x]+self.dat[2*x+1])
  def querry(self,u,v):
    u+=self.size
    v+=self.size
    score=0
    while u<v:
      if u&1:
        score+=self.dat[u]
        u+=1
      if v&1:
        v-=1
        score+=self.dat[v]
      u//=2
      v//=2
    return score
N=int(input())
A=list(map(int,input().split()))
mod=998244353
u=[1]*(N+1)
for i in range(1,N+1):
  u[i]=u[i-1]*i
u2=[1]*(N+1)
for i in range(1,N+1):
  ans=1
  w=u[i]
  n=mod-2
  while n>0:
    if n&1:
      ans*=w
      ans%=mod
    w**=2
    w%=mod
    n//=2
  u2[i]=ans
def ncm(x,y):
  ans=u[x]
  ans*=u2[y]
  ans%=mod
  ans*=u2[x-y]
  ans%=mod
  return ans
Z0=segtree(N)
L=[]
for i in range(N):
  L.append(A[i]*10**6+i)
L.sort()
result=0
for i in range(N):
  pos=L[i]%(10**6)
  x1=Z0.querry(0,pos)
  x2=Z0.querry(pos+1,N)
  y1=pos-x1
  y2=(N-1-pos)-x2
  w=ncm(x1+y2,x1)*ncm(x2+y1,y1)
  w%=mod
  result+=w
  result%=mod
  Z0.update(pos,1)
print(result)
0