結果

問題 No.1234 典型RMQ
ユーザー marroncastlemarroncastle
提出日時 2020-09-18 22:46:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 724 ms / 2,000 ms
コード長 1,484 bytes
コンパイル時間 393 ms
コンパイル使用メモリ 87,140 KB
実行使用メモリ 96,416 KB
最終ジャッジ日時 2023-08-08 18:49:43
合計ジャッジ時間 16,533 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,400 KB
testcase_01 AC 70 ms
71,224 KB
testcase_02 AC 70 ms
71,404 KB
testcase_03 AC 71 ms
71,132 KB
testcase_04 AC 71 ms
71,300 KB
testcase_05 AC 72 ms
71,332 KB
testcase_06 AC 665 ms
92,252 KB
testcase_07 AC 516 ms
87,692 KB
testcase_08 AC 705 ms
95,864 KB
testcase_09 AC 616 ms
89,692 KB
testcase_10 AC 690 ms
94,356 KB
testcase_11 AC 676 ms
91,064 KB
testcase_12 AC 617 ms
88,332 KB
testcase_13 AC 525 ms
87,600 KB
testcase_14 AC 618 ms
88,404 KB
testcase_15 AC 600 ms
88,988 KB
testcase_16 AC 692 ms
94,496 KB
testcase_17 AC 618 ms
88,752 KB
testcase_18 AC 489 ms
86,732 KB
testcase_19 AC 724 ms
96,064 KB
testcase_20 AC 592 ms
95,068 KB
testcase_21 AC 659 ms
91,316 KB
testcase_22 AC 665 ms
96,384 KB
testcase_23 AC 678 ms
96,320 KB
testcase_24 AC 652 ms
96,092 KB
testcase_25 AC 658 ms
96,224 KB
testcase_26 AC 663 ms
96,416 KB
testcase_27 AC 70 ms
71,096 KB
testcase_28 AC 70 ms
71,556 KB
testcase_29 AC 71 ms
71,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# N: 処理する区間の長さ
N = int(input())
INF = float('inf')

LV = (N-1).bit_length()
N0 = 2**LV
data = [0]*(2*N0)
lazy = [0]*(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 not v:
      continue
    lazy[2*i-1] += v; lazy[2*i] += v
    data[2*i-1] += v; data[2*i] += v
    lazy[i-1] = 0

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

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

# 区間[l, r)内の最小値を求める
def query(l, r):
  propagates(*gindex(l, r))
  L = N0 + l; R = N0 + r

  s = INF
  while L < R:
    if R & 1:
      R -= 1
      s = min(s, data[R-1])
    if L & 1:
      s = min(s, data[L-1])
      L += 1
    L >>= 1; R >>= 1
  return s

A = list(map(int, input().split()))
for i in range(N):
  update(i,i+1,A[i])
Q = int(input())
ans = []
for _ in range(Q):
  k,l,r,c = map(int, input().split())
  if k==1:
    update(l-1,r,c)
  else:
    ans.append(query(l-1,r))
print(*ans, sep='\n')
0