結果

問題 No.230 Splarraay スプラレェーイ
ユーザー 👑 timitimi
提出日時 2020-12-16 14:09:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,098 ms / 5,000 ms
コード長 1,946 bytes
コンパイル時間 332 ms
コンパイル使用メモリ 81,860 KB
実行使用メモリ 124,144 KB
最終ジャッジ日時 2023-10-20 09:35:59
合計ジャッジ時間 9,440 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,556 KB
testcase_01 AC 36 ms
53,556 KB
testcase_02 AC 37 ms
53,556 KB
testcase_03 AC 36 ms
53,556 KB
testcase_04 AC 39 ms
53,556 KB
testcase_05 AC 123 ms
76,864 KB
testcase_06 AC 280 ms
80,296 KB
testcase_07 AC 123 ms
76,844 KB
testcase_08 AC 214 ms
78,832 KB
testcase_09 AC 633 ms
98,116 KB
testcase_10 AC 596 ms
94,984 KB
testcase_11 AC 488 ms
87,852 KB
testcase_12 AC 639 ms
98,380 KB
testcase_13 AC 308 ms
80,616 KB
testcase_14 AC 407 ms
106,628 KB
testcase_15 AC 773 ms
103,032 KB
testcase_16 AC 891 ms
112,480 KB
testcase_17 AC 1,098 ms
124,144 KB
testcase_18 AC 629 ms
102,132 KB
testcase_19 AC 770 ms
105,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
Q=int(input())
A,B=[],[]
D=[list(map(int, input().split())) for i in range(Q)]
# N: 処理する区間の長さ
LV = (N-1).bit_length()
N0 = 2**LV
data = [0]*(2*N0)
lazy = [None]*(2*N0)

def gindex(l, r):
    L = (l + N0) >> 1; R = (r + N0) >> 1
    lc = 0 if l & 1 else (L & -L).bit_length()
    rc = 0 if r & 1 else (R & -R).bit_length()
    for i in range(LV):
        if rc <= i:
            yield R
        if L < R and lc <= i:
            yield L
        L >>= 1; R >>= 1

# 遅延伝搬処理
def propagates(*ids):
    for i in reversed(ids):
        v = lazy[i-1]
        if v is None:
            continue
        lazy[2*i-1] = lazy[2*i] = data[2*i-1] = data[2*i] = v >> 1
        lazy[i-1] = None

# 区間[l, r)をxに更新
def update(l, r, x):
    *ids, = gindex(l, r)
    propagates(*ids)

    L = N0 + l; R = N0 + r
    v = x
    while L < R:
        if R & 1:
            R -= 1
            lazy[R-1] = data[R-1] = v
        if L & 1:
            lazy[L-1] = data[L-1] = v
            L += 1
        L >>= 1; R >>= 1; v <<= 1
    for i in ids:
        data[i-1] = data[2*i-1] + data[2*i]

# 区間[l, r)内の合計を求める
def query(l, r):
    propagates(*gindex(l, r))
    L = N0 + l; R = N0 + r
    s = 0
    while L < R:
        if R & 1:
            R -= 1
            s += data[R-1]
        if L & 1:
            s += data[L-1]
            L += 1
        L >>= 1; R >>= 1
    return s

for i in range(Q):
  x,l,r=D[i]
  if x==1:
    update(l,r+1,1)
  elif x==2:
    update(l,r+1,0)
  else:
    d=query(l,r+1)
    A.append(d)
d=query(0,N)
A.append(d)

LV = (N-1).bit_length()
N0 = 2**LV
data = [0]*(2*N0)
lazy = [None]*(2*N0)
for i in range(Q):
  x,l,r=D[i]
  if x==2:
    update(l,r+1,1)
  elif x==1:
    update(l,r+1,0)
  else:
    d=query(l,r+1)
    B.append(d)
d=query(0,N)
B.append(d)
a,b=A[-1],B[-1]
for i in range(len(A)-1):
  if A[i]>B[i]:
    a+=A[i]
  elif A[i]<B[i]:
    b+=B[i]
print(a,b)
    
0