結果

問題 No.2171 OR Assignment
ユーザー titiatitia
提出日時 2022-12-25 01:11:58
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 2,058 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 162,048 KB
最終ジャッジ日時 2024-04-29 07:04:40
合計ジャッジ時間 21,307 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
162,048 KB
testcase_01 AC 43 ms
52,352 KB
testcase_02 AC 42 ms
51,840 KB
testcase_03 AC 42 ms
52,096 KB
testcase_04 AC 42 ms
51,840 KB
testcase_05 AC 43 ms
51,840 KB
testcase_06 AC 42 ms
52,096 KB
testcase_07 AC 42 ms
52,096 KB
testcase_08 AC 41 ms
52,352 KB
testcase_09 AC 42 ms
52,224 KB
testcase_10 AC 42 ms
52,736 KB
testcase_11 AC 43 ms
52,480 KB
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 AC 966 ms
107,520 KB
testcase_16 AC 1,362 ms
107,520 KB
testcase_17 AC 942 ms
104,376 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

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

def seg_function(x,y): # Segment treeで扱うfunction
    return x|y

seg_el=1<<(N.bit_length()) # Segment treeの台の要素数
SEG=[0]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化

for i in range(N): # Aを対応する箇所へupdate
    SEG[i+seg_el]=A[i]

for i in range(seg_el-1,0,-1): # 親の部分もupdate
    SEG[i]=seg_function(SEG[i*2],SEG[i*2+1])

def update(n,x,seg_el): # A[n]をxへ更新
    i=n+seg_el
    SEG[i]=x
    i>>=1 # 子ノードへ
    
    while i!=0:
        SEG[i]=seg_function(SEG[i*2],SEG[i*2+1])
        i>>=1
        
def getvalues(l,r): # 区間[l,r)に関するseg_functionを調べる
    L=l+seg_el
    R=r+seg_el
    ANS=0

    while L<R:
        if L & 1:
            ANS=seg_function(ANS , SEG[L])
            L+=1

        if R & 1:
            R-=1
            ANS=seg_function(ANS , SEG[R])
        L>>=1
        R>>=1

    return ANS

def bisect_on_SEG(l,x): # l以上で、x以上の最小のindexを返す。ただし、存在しない場合はNを返す。
    L=l+seg_el
    R=seg_el*2-1
    while L<R:
        if SEG[L]>=x:
            break
        if L & 1:
            L+=1
        L>>=1
        R>>=1
 
    if SEG[L]<x:
        return N
 
    while L<seg_el:
        if SEG[L*2]>=x:
            L=L*2
        else:
            L=L*2+1
 
    return L-seg_el

mod=998244353

IND=[0]
DP=[1]

for i in range(1,N):
    NDP=[]
    NIND=[]
    a=A[i]
    s=i
    OK=i
    while True:
        NG=-1
        while OK>NG+1:
            mid=(OK+NG)//2

            if getvalues(mid,i+1)==a:
                OK=mid
            else:
                NG=mid

        score=0
        for ix in range(len(IND)):
            if IND[ix]<=s:
                score=(score+DP[ix])%mod

        NDP.append(score)
        NIND.append(OK)
        if OK==0:
            break
        else:
            OK=OK-1
            a|=A[OK]
            s=OK

    DP=NDP
    IND=NIND

print(sum(DP)%mod)
0