結果

問題 No.2250 Split Permutation
ユーザー sotanishysotanishy
提出日時 2023-03-17 22:14:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 565 ms / 3,000 ms
コード長 950 bytes
コンパイル時間 340 ms
コンパイル使用メモリ 81,504 KB
実行使用メモリ 109,196 KB
最終ジャッジ日時 2023-10-18 15:07:47
合計ジャッジ時間 8,645 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,388 KB
testcase_01 AC 38 ms
53,388 KB
testcase_02 AC 39 ms
53,388 KB
testcase_03 AC 38 ms
53,388 KB
testcase_04 AC 39 ms
53,388 KB
testcase_05 AC 39 ms
53,388 KB
testcase_06 AC 38 ms
53,388 KB
testcase_07 AC 38 ms
53,388 KB
testcase_08 AC 39 ms
53,388 KB
testcase_09 AC 38 ms
53,388 KB
testcase_10 AC 39 ms
53,388 KB
testcase_11 AC 37 ms
53,388 KB
testcase_12 AC 38 ms
53,388 KB
testcase_13 AC 38 ms
53,388 KB
testcase_14 AC 38 ms
53,388 KB
testcase_15 AC 37 ms
53,388 KB
testcase_16 AC 38 ms
53,388 KB
testcase_17 AC 38 ms
53,388 KB
testcase_18 AC 565 ms
109,196 KB
testcase_19 AC 514 ms
105,144 KB
testcase_20 AC 453 ms
101,568 KB
testcase_21 AC 292 ms
92,720 KB
testcase_22 AC 419 ms
98,504 KB
testcase_23 AC 131 ms
81,116 KB
testcase_24 AC 408 ms
98,504 KB
testcase_25 AC 556 ms
109,196 KB
testcase_26 AC 231 ms
90,592 KB
testcase_27 AC 113 ms
78,968 KB
testcase_28 AC 148 ms
82,872 KB
testcase_29 AC 563 ms
109,196 KB
testcase_30 AC 154 ms
83,784 KB
testcase_31 AC 91 ms
77,192 KB
testcase_32 AC 176 ms
85,460 KB
testcase_33 AC 328 ms
93,268 KB
testcase_34 AC 133 ms
81,120 KB
testcase_35 AC 240 ms
89,092 KB
testcase_36 AC 174 ms
85,284 KB
testcase_37 AC 557 ms
109,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

class FenwickTree:
    def __init__(self, size):
        self.data = [0] * (size + 1)
        self.size = size

    # i is exclusive
    def prefix_sum(self, i):
        s = 0
        while i > 0:
            s = (s + self.data[i]) % mod
            i -= i & -i
        return s

    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.data[i] = (self.data[i] + x) % mod
            i += i & -i

mod = 998244353
N = int(input())
P = list(map(lambda x: int(x)-1, input().split()))
pow2 = [1] * (N+1)
for i in range(1, N+1):
    pow2[i] = pow2[i-1] * 2 % mod
ft_cnt = FenwickTree(N)
ft_val = FenwickTree(N)
ans = 0
for i, x in enumerate(P):
    cnt = ft_cnt.prefix_sum(N) - ft_cnt.prefix_sum(x)
    val = ft_val.prefix_sum(N) - ft_val.prefix_sum(x)
    ans = (ans + pow2[N-1] * (cnt - val * pow(pow2[i], mod-2, mod))) % mod
    ft_cnt.add(x, 1)
    ft_val.add(x, pow2[i])
print(ans)
0