結果

問題 No.1441 MErGe
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-06-10 10:23:16
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,151 bytes
コンパイル時間 217 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 126,300 KB
最終ジャッジ日時 2024-05-07 03:34:22
合計ジャッジ時間 11,304 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
51,840 KB
testcase_01 AC 36 ms
51,840 KB
testcase_02 AC 35 ms
52,096 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 292 ms
125,668 KB
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def main0(n,q,a,tlr):
  pass

# 0-indexed binary indexed tree
class BIT:
  def __init__(self, n):
    self.n = n
    self.data = [0]*(n+1)
    self.el = [0]*(n+1)
  # sum of [0,i) sum(a[:i])
  def sum(self, i):
    if i==0:return 0
    s = 0
    while i > 0:
      s += self.data[i]
      i -= i & -i
    return s
  def add(self, i, x):
    i+=1
    self.el[i] += x
    while i <= self.n:
      self.data[i] += x
      i += i & -i
  # sum of [l,r)   sum(a[l:r])
  def sumlr(self, i, j):
    return self.sum(j) - self.sum(i)
  # a[i]
  def get(self,i):
    i+=1
    return self.el[i]

def main1(n,q,a,tlr):
  # 削除前と削除後のidxの紐づけを保持する。
  # f:i->j このとき必ずi>=j
  bit=BIT(n+1)
  sa=[0]
  for x in a:
    sa.append(sa[-1]+x)
  ret=[]
  for t,l,r in tlr:
    l,r=l-1,r-1
    if t==1:
      bit.add(l+1,r-l)
    else:
      ll=l+bit.sum(l+1)
      rr=r+bit.sum(r+1)
      ret.append(sa[rr+1]-sa[ll])
  return ret
    
if __name__=='__main__':
  n,q=map(int,input().split())
  a=list(map(int,input().split()))
  tlr=[list(map(int,input().split())) for _ in range(q)]
  ret1=main1(n,q,a,tlr)
  print(*ret1,sep="\n")
0