結果

問題 No.230 Splarraay スプラレェーイ
ユーザー 👑 timitimi
提出日時 2020-12-16 14:07:53
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 3,934 ms / 5,000 ms
コード長 1,943 bytes
コンパイル時間 118 ms
コンパイル使用メモリ 12,136 KB
実行使用メモリ 38,436 KB
最終ジャッジ日時 2023-10-20 09:35:20
合計ジャッジ時間 26,586 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,388 KB
testcase_01 AC 31 ms
10,388 KB
testcase_02 AC 31 ms
10,388 KB
testcase_03 AC 32 ms
10,388 KB
testcase_04 AC 32 ms
10,388 KB
testcase_05 AC 49 ms
10,592 KB
testcase_06 AC 209 ms
12,768 KB
testcase_07 AC 45 ms
10,504 KB
testcase_08 AC 70 ms
11,012 KB
testcase_09 AC 1,823 ms
24,856 KB
testcase_10 AC 1,345 ms
26,472 KB
testcase_11 AC 1,027 ms
18,148 KB
testcase_12 AC 1,797 ms
24,836 KB
testcase_13 AC 290 ms
13,200 KB
testcase_14 AC 1,891 ms
37,180 KB
testcase_15 AC 3,030 ms
34,832 KB
testcase_16 AC 3,444 ms
37,736 KB
testcase_17 AC 3,934 ms
38,436 KB
testcase_18 AC 2,629 ms
36,976 KB
testcase_19 AC 2,422 ms
27,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
N
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