結果

問題 No.789 範囲の合計
ユーザー 👑 horiesinitihoriesiniti
提出日時 2018-03-17 18:03:39
言語 Ruby
(3.3.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 523 bytes
コンパイル時間 362 ms
コンパイル使用メモリ 11,456 KB
実行使用メモリ 55,000 KB
最終ジャッジ日時 2023-09-07 11:53:12
合計ジャッジ時間 5,193 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def f(x,l,r)
	if l==r
		$hs[[l,r]]+=1
	elsif (l<=x&&x<=r)
		$hs[[l,r]]+=1
		m=(l+r)/2
		f(x,l,m)
		f(x,m+1,r)
	end
end
def sum(l,r,l2,r2)
	if $hs.key?([l,r])==false
		return 0
	else
		if r<l2
			return 0
		end
		if r2<l 
			return 0
		end
		if(l2<=l&&r<=r2)
			return $hs[[l,r]]
		end
		m=(l+r)/2
		res=sum(l,m,l2,r2)
		res+=sum(m+1,r,l2,r2)
		return res
	end
end
$hs=Hash.new(0)
n=gets.to_i
ans=0
r=1073741823
n.times{
	x=gets.split.map{|e| e.to_i}
	if x[0]==0
		f(x[1],0,r)
	else
		ans+=sum(0,r,x[1],x[2])
	end
}
puts ans
0