結果
| 問題 | No.230 Splarraay スプラレェーイ |
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2026-03-10 03:34:14 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 271 ms / 5,000 ms |
| コード長 | 2,830 bytes |
| 記録 | |
| コンパイル時間 | 164 ms |
| コンパイル使用メモリ | 85,108 KB |
| 実行使用メモリ | 86,468 KB |
| 最終ジャッジ日時 | 2026-03-10 03:34:20 |
| 合計ジャッジ時間 | 4,333 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
import sys
input = sys.stdin.readline
N=int(input())
Q=int(input())
# 非再帰遅延伝搬セグ木(範囲更新, 範囲和出力)
# 高々N点を更新
seg_el=1<<(N.bit_length()) # Segment treeの台の要素数
seg_height=1+N.bit_length() # Segment treeのたかさ
SEG=[0]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化
LAZY=[None]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化
def indexes(L,R): # 遅延伝搬すべきノードのリストを返す. (つまり, updateやgetvaluesで見るノードより上にあるノードたち)
INDLIST=[]
R-=1
L>>=1
R>>=1
while L!=R:
if L>R:
INDLIST.append(L)
L>>=1
else:
INDLIST.append(R)
R>>=1
while L!=0:
INDLIST.append(L)
L>>=1
return INDLIST
def updates(l,r,x): # 区間[l,r)をxに更新
L=l+seg_el
R=r+seg_el
L//=(L & (-L))
R//=(R & (-R))
UPIND=indexes(L,R)
for ind in UPIND[::-1]: # 遅延伝搬
if LAZY[ind]!=None:
update_lazy = LAZY[ind] *(1<<(seg_height - 1 - (ind.bit_length())))
LAZY[ind<<1]=LAZY[1+(ind<<1)]=LAZY[ind]
SEG[ind<<1]=SEG[1+(ind<<1)]=update_lazy
LAZY[ind]=None
while L!=R:
if L > R:
SEG[L]=x * (1<<(seg_height - (L.bit_length())))
LAZY[L]=x
L+=1
L//=(L & (-L))
else:
R-=1
SEG[R]=x * (1<<(seg_height - (R.bit_length())))
LAZY[R]=x
R//=(R & (-R))
for ind in UPIND:
SEG[ind]=SEG[ind<<1]+SEG[1+(ind<<1)]
def getvalues(l,r): # 区間[l,r)に関する和を調べる
L=l+seg_el
R=r+seg_el
L//=(L & (-L))
R//=(R & (-R))
UPIND=indexes(L,R)
for ind in UPIND[::-1]: # 遅延伝搬
if LAZY[ind]!=None:
update_lazy = LAZY[ind] *(1<<(seg_height - 1 - (ind.bit_length())))
LAZY[ind<<1]=LAZY[1+(ind<<1)]=LAZY[ind]
SEG[ind<<1]=SEG[1+(ind<<1)]=update_lazy
LAZY[ind]=None
ANS=0
while L!=R:
if L > R:
ANS+=SEG[L]
L+=1
L//=(L & (-L))
else:
R-=1
ANS+=SEG[R]
R//=(R & (-R))
return ANS
A=0
B=0
for tests in range(Q):
L=list(map(int,input().split()))
if L[0]==0:
l,r=L[1:]
score=getvalues(l,r+1)
a=score%(10**9)
b=score//(10**9)
if a>b:
A+=a
if b>a:
B+=b
elif L[0]==1:
l,r=L[1:]
updates(l,r+1,1)
else:
l,r=L[1:]
updates(l,r+1,10**9)
score=getvalues(0,N)
a=score%(10**9)
b=score//(10**9)
A+=a
B+=b
print(A,B)
titia