結果

問題 No.1000 Point Add and Array Add
ユーザー hoktohokto
提出日時 2020-03-03 08:12:45
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 2,040 bytes
コンパイル時間 317 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 17,664 KB
最終ジャッジ日時 2024-04-21 23:14:22
合計ジャッジ時間 7,670 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
17,664 KB
testcase_01 AC 93 ms
12,160 KB
testcase_02 AC 90 ms
12,288 KB
testcase_03 AC 91 ms
12,160 KB
testcase_04 AC 90 ms
12,160 KB
testcase_05 AC 91 ms
12,288 KB
testcase_06 AC 90 ms
12,160 KB
testcase_07 AC 90 ms
12,160 KB
testcase_08 AC 91 ms
12,160 KB
testcase_09 AC 92 ms
12,160 KB
testcase_10 AC 92 ms
12,160 KB
testcase_11 AC 90 ms
12,160 KB
testcase_12 AC 1,196 ms
12,288 KB
testcase_13 AC 172 ms
12,160 KB
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

class LazySegTree
  attr_accessor:node,:n,:lazy
  def initialize(n)
    @n=1
    @n*=2 while @n<n
    @node=array(2*@n-1,1,0)
    @lazy=array(2*@n-1,1,0)
  end

  def lazy_eval(i,l,r)
    unless @lazy[i].zero?
      @node[i]+=@lazy[i]
      if r-l>1
        @lazy[i*2+1]+=@lazy[i]/2
        @lazy[i*2+2]+=@lazy[i]/2
      end
      @lazy[i]=0
    end
  end
  def add(s,t,x,i,l,r)
    lazy_eval(i,l,r)
    return if r<=s or t<=l
    if s<=l and r<=t
      @lazy[i]=(r-l)*x
      lazy_eval(i,l,r)
    else
      mid=(l+r)/2
      add(s,t,x,i*2+1,l,mid)
      add(s,t,x,i*2+2,mid,r)
      @node[i]=@node[i*2+1]+@node[i*2+2]
    end
  end

  def getSum(s,t,i,l,r)
    return 0 if r<=s or t<=l
    lazy_eval(i,l,r)
    return @node[i] if s<=l and r<=t
    mid=(l+r)/2
    leaf_l=getSum(s,t,i*2+1,l,mid)
    leaf_r=getSum(s,t,i*2+2,mid,r)
    return leaf_l+leaf_r
  end
end
n,q=get_i
lst=LazySegTree.new(n)
a=get_i
q.times do
  c,x,y=get
  if c=="A"
    x=x.to_i-1
    y=y.to_i
    a[x]+=y
  else
    x=x.to_i-1
    y=y.to_i-1
    for i in x..y
      lst.add(i,i+1,a[i],0,0,lst.n)
    end
  end
end
ans=[]
n.times do|i|
  ans.push(lst.getSum(i,i+1,0,0,lst.n))
end
puts ans.join(" ")
0