結果

問題 No.2250 Split Permutation
ユーザー convexineqconvexineq
提出日時 2023-06-29 15:14:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 410 ms / 3,000 ms
コード長 1,694 bytes
コンパイル時間 356 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 119,060 KB
最終ジャッジ日時 2023-09-20 10:38:05
合計ジャッジ時間 9,412 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,268 KB
testcase_01 AC 74 ms
71,272 KB
testcase_02 AC 71 ms
71,264 KB
testcase_03 AC 71 ms
71,560 KB
testcase_04 AC 71 ms
71,400 KB
testcase_05 AC 72 ms
71,636 KB
testcase_06 AC 70 ms
71,288 KB
testcase_07 AC 74 ms
71,356 KB
testcase_08 AC 75 ms
71,292 KB
testcase_09 AC 72 ms
71,256 KB
testcase_10 AC 72 ms
71,132 KB
testcase_11 AC 72 ms
71,272 KB
testcase_12 AC 70 ms
71,264 KB
testcase_13 AC 72 ms
71,332 KB
testcase_14 AC 72 ms
71,320 KB
testcase_15 AC 71 ms
71,440 KB
testcase_16 AC 72 ms
71,480 KB
testcase_17 AC 72 ms
71,488 KB
testcase_18 AC 404 ms
118,944 KB
testcase_19 AC 364 ms
109,976 KB
testcase_20 AC 330 ms
105,472 KB
testcase_21 AC 227 ms
100,648 KB
testcase_22 AC 318 ms
112,212 KB
testcase_23 AC 134 ms
82,416 KB
testcase_24 AC 317 ms
112,072 KB
testcase_25 AC 405 ms
119,060 KB
testcase_26 AC 185 ms
93,712 KB
testcase_27 AC 121 ms
80,016 KB
testcase_28 AC 143 ms
84,372 KB
testcase_29 AC 410 ms
119,044 KB
testcase_30 AC 147 ms
85,696 KB
testcase_31 AC 115 ms
78,840 KB
testcase_32 AC 161 ms
87,556 KB
testcase_33 AC 252 ms
103,784 KB
testcase_34 AC 132 ms
82,484 KB
testcase_35 AC 193 ms
94,728 KB
testcase_36 AC 161 ms
87,820 KB
testcase_37 AC 409 ms
118,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class BIT: #0-indexed
    __slots__ = ["size", "tree","depth","n0"]
    def __init__(self, n):
        self.size = n
        self.tree = [0]*(n+1)
        self.depth = n.bit_length()
        self.n0 = 1<<self.depth

    def get_sum(self, i): #a_0 + ... + a_{i} #閉区間
        s = 0; i += 1
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def range_sum(self,l,r): #a_l + ... + a_r 閉区間
        return self.get_sum(r) - self.get_sum(l-1) 

    def range_sum_larger(self,l): #a_l + ... (端まで)
        return self.get_sum(self.size-1) - (self.get_sum(l-1) if l else 0)
    
    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def bisect_left(self,w):
        #和が w 以上になる最小の index
        #w が存在しない場合 self.size を返す
        if w <= 0: return 0
        x,k = 0,self.n0
        for _ in range(self.depth):
            k >>= 1
            if x+k <= self.size and self.tree[x+k] < w:
                w -= self.tree[x+k]
                x += k
        return x

import sys
readline = sys.stdin.readline
 
#n = int(readline())
#*a, = map(int,readline().split())
# b = [list(map(int,readline().split())) for _ in range()]
 
n = int(readline())
*p, = map(int,readline().split())


b1 = BIT(n+1)
b2 = BIT(n+2)
ans = 0
MOD = 998244353
pow2 = [1]
inv2 = (MOD+1)//2
for i in range(n+2):
    pow2.append(pow2[-1]*2%MOD)

for i in range(n):
    s = b1.range_sum_larger(p[i])
    t = b2.range_sum_larger(p[i])
    ans += pow2[n-1]*s
    ans -= pow2[n-1-i]*t
    ans %= MOD
    b1.add(p[i],1)
    b2.add(p[i],pow2[i])

print(ans)




0