結果
| 問題 |
No.2616 中央番目の中央値
|
| コンテスト | |
| ユーザー |
ゼット
|
| 提出日時 | 2024-01-26 23:20:21 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 642 ms / 2,000 ms |
| コード長 | 1,164 bytes |
| コンパイル時間 | 343 ms |
| コンパイル使用メモリ | 82,688 KB |
| 実行使用メモリ | 149,804 KB |
| 最終ジャッジ日時 | 2024-09-28 09:05:48 |
| 合計ジャッジ時間 | 12,606 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 37 |
ソースコード
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
u[i]%=mod
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)
ゼット