結果

問題 No.1709 Indistinguishable by MEX
ユーザー titiatitia
提出日時 2021-10-16 03:01:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,192 ms / 2,000 ms
コード長 950 bytes
コンパイル時間 178 ms
コンパイル使用メモリ 11,956 KB
実行使用メモリ 31,992 KB
最終ジャッジ日時 2023-10-17 22:02:03
合計ジャッジ時間 17,873 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,112 KB
testcase_01 AC 29 ms
10,112 KB
testcase_02 AC 28 ms
10,112 KB
testcase_03 AC 29 ms
10,112 KB
testcase_04 AC 29 ms
10,112 KB
testcase_05 AC 29 ms
10,112 KB
testcase_06 AC 28 ms
10,112 KB
testcase_07 AC 29 ms
10,112 KB
testcase_08 AC 863 ms
28,992 KB
testcase_09 AC 669 ms
25,544 KB
testcase_10 AC 715 ms
24,852 KB
testcase_11 AC 590 ms
21,964 KB
testcase_12 AC 537 ms
21,872 KB
testcase_13 AC 899 ms
26,392 KB
testcase_14 AC 830 ms
25,916 KB
testcase_15 AC 812 ms
26,952 KB
testcase_16 AC 1,085 ms
30,884 KB
testcase_17 AC 973 ms
30,504 KB
testcase_18 AC 1,070 ms
31,992 KB
testcase_19 AC 1,055 ms
31,992 KB
testcase_20 AC 1,061 ms
31,992 KB
testcase_21 AC 1,192 ms
31,992 KB
testcase_22 AC 1,178 ms
31,992 KB
testcase_23 AC 625 ms
31,992 KB
testcase_24 AC 624 ms
31,992 KB
testcase_25 AC 637 ms
31,992 KB
testcase_26 AC 29 ms
10,112 KB
testcase_27 AC 345 ms
22,800 KB
testcase_28 AC 320 ms
21,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N=int(input())
P=list(map(int,input().split()))
mod=998244353
ANS=1

P_INV=[-1]*N

for i in range(N):
    P_INV[P[i]]=i

LEN=N+10
BIT=[0]*(LEN+1) # 1-indexedなtree. 配列BITの長さはLEN+1にしていることに注意。

def update(v,w): # index vにwを加える
    while v<=LEN:
        BIT[v]+=w
        v+=(v&(-v)) # v&(-v)で、最も下の立っているビット. 自分を含む大きなノードへ. たとえばv=3→v=4

def getvalue(v): # [1,v]の区間の和を求める
    ANS=0
    while v!=0:
        ANS+=BIT[v]
        v-=(v&(-v)) # 自分より小さい自分の和を構成するノードへ. たとえばv=14→v=12へ
    return ANS

L=10**8
R=-100

for i in range(N):
    x=P_INV[i]+5

    L2=min(L,x)
    R2=max(R,x)

    if R2-L2==R-L:
        sc=(R-L+1)-(getvalue(R)-getvalue(L-1))

        ANS*=sc
        ANS%=mod

    update(x,1)
        
    L=L2
    R=R2

print(ANS)
    
0