結果

問題 No.2250 Split Permutation
ユーザー titiatitia
提出日時 2023-03-18 00:02:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 496 ms / 3,000 ms
コード長 1,178 bytes
コンパイル時間 201 ms
コンパイル使用メモリ 81,812 KB
実行使用メモリ 107,632 KB
最終ジャッジ日時 2023-10-18 16:40:27
合計ジャッジ時間 7,938 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,560 KB
testcase_01 AC 38 ms
53,560 KB
testcase_02 AC 36 ms
53,560 KB
testcase_03 AC 41 ms
53,560 KB
testcase_04 AC 35 ms
53,560 KB
testcase_05 AC 37 ms
53,560 KB
testcase_06 AC 37 ms
53,560 KB
testcase_07 AC 38 ms
53,560 KB
testcase_08 AC 37 ms
53,560 KB
testcase_09 AC 36 ms
53,560 KB
testcase_10 AC 37 ms
53,560 KB
testcase_11 AC 37 ms
53,560 KB
testcase_12 AC 37 ms
53,560 KB
testcase_13 AC 35 ms
53,560 KB
testcase_14 AC 37 ms
53,560 KB
testcase_15 AC 37 ms
53,560 KB
testcase_16 AC 36 ms
53,560 KB
testcase_17 AC 36 ms
53,560 KB
testcase_18 AC 477 ms
107,632 KB
testcase_19 AC 449 ms
103,848 KB
testcase_20 AC 395 ms
100,268 KB
testcase_21 AC 245 ms
92,392 KB
testcase_22 AC 352 ms
97,472 KB
testcase_23 AC 131 ms
79,196 KB
testcase_24 AC 362 ms
97,472 KB
testcase_25 AC 496 ms
107,632 KB
testcase_26 AC 185 ms
87,624 KB
testcase_27 AC 91 ms
77,368 KB
testcase_28 AC 122 ms
80,680 KB
testcase_29 AC 489 ms
107,632 KB
testcase_30 AC 131 ms
81,488 KB
testcase_31 AC 76 ms
76,080 KB
testcase_32 AC 145 ms
83,284 KB
testcase_33 AC 281 ms
94,524 KB
testcase_34 AC 111 ms
79,220 KB
testcase_35 AC 203 ms
88,496 KB
testcase_36 AC 143 ms
82,680 KB
testcase_37 AC 480 ms
107,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N=int(input())
P=list(map(int,input().split()))

mod=998244353

BIT=[0]*(N+2) # 出現回数をbit indexed treeの形でもっておく.
LEN=N+1
def update(v,w): # index vにwを加える
    while v<=LEN:
        BIT[v]+=w
        v+=(v&(-v)) # 自分を含む大きなノードへ. たとえばv=3→v=4

def getvalue(v): # MIN~vの区間の和を求める
    ANS=0
    while v!=0:
        ANS+=BIT[v]
        v-=(v&(-v)) # たとえばv=3→v=2へ
    return ANS

BIT2=[0]*(N+2) # 出現回数をbit indexed treeの形でもっておく.

def update2(v,w): # index vにwを加える
    while v<=LEN:
        BIT2[v]+=w
        v+=(v&(-v)) # 自分を含む大きなノードへ. たとえばv=3→v=4

def getvalue2(v): # MIN~vの区間の和を求める
    ANS=0
    while v!=0:
        ANS+=BIT2[v]
        v-=(v&(-v)) # たとえばv=3→v=2へ
    return ANS

MAX=pow(2,N-1,mod)
ANS=0
for i in range(N):
    p=P[i]
    ko=i-getvalue2(p)
    kieru=getvalue(LEN)-getvalue(p)
    
    update(p,pow(2,i,mod))
    update2(p,1)

    ANS+=MAX*ko
    ANS-=kieru*pow(2,N-1-i,mod)
    #print(ko,ANS,kieru)
    ANS%=mod

print(ANS%mod)
0