結果
| 問題 |
No.2250 Split Permutation
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-03-17 23:24:00 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 385 ms / 3,000 ms |
| コード長 | 808 bytes |
| コンパイル時間 | 175 ms |
| コンパイル使用メモリ | 82,404 KB |
| 実行使用メモリ | 114,764 KB |
| 最終ジャッジ日時 | 2024-09-18 12:27:29 |
| 合計ジャッジ時間 | 6,551 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 |
ソースコード
import sys
input = sys.stdin.readline
from collections import *
class BIT:
def __init__(self, n):
self.n = n
self.bit = [0]*(n+1)
def add(self, i, x):
i += 1
while i<=self.n:
self.bit[i] += x
i += i&(-i)
def acc(self, i):
s = 0
while i>0:
s += self.bit[i]
i -= i&(-i)
return s
N = int(input())
P = list(map(int, input().split()))
P = list(map(lambda x: x-1, P))
MOD = 998244353
bit = BIT(N)
inv = 0
for i in range(N):
inv += i-bit.acc(P[i])
bit.add(P[i], 1)
ans = inv*pow(2, N-1, MOD)%MOD
bit = BIT(N)
for i in range(N):
ans -= pow(2, N-1-i, MOD)*(bit.acc(N)-bit.acc(P[i]))%MOD
ans %= MOD
bit.add(P[i], pow(2, i, MOD))
print(ans)