結果

問題 No.2171 OR Assignment
ユーザー titia
提出日時 2022-12-25 01:50:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 714 ms / 3,500 ms
コード長 1,089 bytes
コンパイル時間 351 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 105,904 KB
最終ジャッジ日時 2024-11-18 08:58:10
合計ジャッジ時間 12,389 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

# 似たような解法は考えていたが、高速化が難しかった。
# 自分が思いついたのはセグ木二分探索だが、TLE。
# 解説を見て、最後に現れたbitを管理する方法があると分かった。。

import sys
input = sys.stdin.readline

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

prev=[0]*30

mod=998244353

IND=[0]
DP=[1]

for i in range(1,N):
    NDP=[]
    NIND=[]
    a=A[i]
    
    for j in range(30):
        if (1<<j) & a!= 0:
            prev[j]=i

    sp=sorted(set(prev)|{i},reverse=True)
    SA=[a]*len(sp)
    now=a
    for j in range(len(sp)):
        now|=A[sp[j]]
        SA[j]=now

    s=i
    score=sum(DP)%mod
    ind=0

    for j in range(len(SA)):
        if j+1<len(SA) and SA[j]==SA[j+1]:
            continue
        else:
            while ind<len(IND) and IND[ind]>s:
                score=(score-DP[ind])%mod
                ind+=1

            NDP.append(score)
            NIND.append(sp[j])

            if j+1<len(sp):
                s=sp[j+1]

    DP=NDP
    IND=NIND
    #print(DP,IND)

print(sum(DP)%mod)
0