結果
問題 |
No.2171 OR Assignment
|
ユーザー |
![]() |
提出日時 | 2022-12-25 01:08:25 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,034 bytes |
コンパイル時間 | 158 ms |
コンパイル使用メモリ | 82,060 KB |
実行使用メモリ | 215,984 KB |
最終ジャッジ日時 | 2024-11-18 08:22:05 |
合計ジャッジ時間 | 78,037 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 16 TLE * 14 |
ソースコード
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 DP=[(0,1)] for i in range(1,N): NDP=[] 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 x,y in DP: if x<=s: score=(score+y)%mod NDP.append((OK,score)) if OK==0: break else: OK=OK-1 a|=A[OK] s=OK DP=NDP #print(DP) ANS=0 for x,y in DP: ANS+=y print(ANS%mod)