結果

問題 No.2250 Split Permutation
ユーザー rlangevinrlangevin
提出日時 2023-11-12 02:14:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 372 ms / 3,000 ms
コード長 1,410 bytes
コンパイル時間 329 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 108,920 KB
最終ジャッジ日時 2023-11-12 02:14:57
合計ジャッジ時間 8,511 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 35 ms
53,460 KB
testcase_02 AC 35 ms
53,460 KB
testcase_03 AC 36 ms
53,460 KB
testcase_04 AC 35 ms
53,460 KB
testcase_05 AC 35 ms
53,460 KB
testcase_06 AC 37 ms
53,460 KB
testcase_07 AC 35 ms
53,460 KB
testcase_08 AC 35 ms
53,460 KB
testcase_09 AC 35 ms
53,460 KB
testcase_10 AC 36 ms
53,460 KB
testcase_11 AC 34 ms
53,460 KB
testcase_12 AC 35 ms
53,460 KB
testcase_13 AC 35 ms
53,460 KB
testcase_14 AC 35 ms
53,460 KB
testcase_15 AC 35 ms
53,460 KB
testcase_16 AC 36 ms
53,460 KB
testcase_17 AC 35 ms
53,460 KB
testcase_18 AC 329 ms
108,920 KB
testcase_19 AC 328 ms
104,928 KB
testcase_20 AC 268 ms
101,336 KB
testcase_21 AC 174 ms
90,848 KB
testcase_22 AC 242 ms
98,552 KB
testcase_23 AC 97 ms
80,700 KB
testcase_24 AC 250 ms
98,564 KB
testcase_25 AC 372 ms
108,920 KB
testcase_26 AC 143 ms
88,220 KB
testcase_27 AC 87 ms
78,512 KB
testcase_28 AC 106 ms
82,244 KB
testcase_29 AC 324 ms
108,920 KB
testcase_30 AC 114 ms
83,152 KB
testcase_31 AC 79 ms
76,272 KB
testcase_32 AC 127 ms
84,768 KB
testcase_33 AC 197 ms
92,976 KB
testcase_34 AC 99 ms
80,716 KB
testcase_35 AC 157 ms
87,084 KB
testcase_36 AC 122 ms
83,984 KB
testcase_37 AC 330 ms
108,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Fenwick_Tree:
    def __init__(self, n):
        self._n = n
        self.data = [0] * n

    def add(self, p, x):
        assert 0 <= p < self._n
        p += 1
        while p <= self._n:
            self.data[p - 1] += x
            p += p & -p

    def sum(self, l, r):
        assert 0 <= l <= r <= self._n
        return self._sum(r) - self._sum(l)

    def _sum(self, r):
        s = 0
        while r > 0:
            s += self.data[r - 1]
            r -= r & -r
        return s

    def get_size(self, x):
        x = self.find(x)
        while r > 0:
            s += self.data[r - 1]
            r -= r & -r
        return s

    def get(self, k):
        k += 1
        x, r = 0, 1
        while r < self._n:
            r <<= 1
        len = r
        while len:
            if x + len - 1 < self._n:
                if self.data[x + len - 1] < k:
                    k -= self.data[x + len - 1]
                    x += len
            len >>= 1
        return x


N = int(input())
P = list(map(int, input().split()))
T1, T2 = Fenwick_Tree(N), Fenwick_Tree(N)
ans = 0
mod = 998244353
inv = pow(2, mod - 2, mod)
N2 = now = pow(2, N - 1, mod)
two = 1
for i in range(N):
    P[i] -= 1
    v1 = T1.sum(P[i], N)
    v2 = T2.sum(P[i], N)
    T1.add(P[i], N2)
    T2.add(P[i], two)
    ans += v1 - v2 * now
    now *= inv
    two *= 2
    ans %= mod
    now %= mod
    two %= mod
    
print(ans)
0