結果

問題 No.1091 Range Xor Query
ユーザー 小野寺健小野寺健
提出日時 2021-11-05 13:30:33
言語 Ruby
(3.3.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 722 bytes
コンパイル時間 56 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 37,384 KB
最終ジャッジ日時 2024-04-23 21:01:43
合計ジャッジ時間 33,263 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
12,288 KB
testcase_01 AC 88 ms
12,288 KB
testcase_02 AC 91 ms
12,160 KB
testcase_03 AC 274 ms
24,448 KB
testcase_04 AC 1,078 ms
23,636 KB
testcase_05 AC 1,207 ms
31,832 KB
testcase_06 AC 105 ms
14,848 KB
testcase_07 AC 1,271 ms
25,584 KB
testcase_08 AC 1,741 ms
31,196 KB
testcase_09 AC 866 ms
21,228 KB
testcase_10 AC 1,238 ms
29,532 KB
testcase_11 AC 1,584 ms
30,540 KB
testcase_12 AC 881 ms
31,572 KB
testcase_13 AC 1,848 ms
31,044 KB
testcase_14 AC 1,317 ms
29,424 KB
testcase_15 AC 1,383 ms
31,172 KB
testcase_16 AC 1,371 ms
26,952 KB
testcase_17 AC 1,964 ms
33,764 KB
testcase_18 AC 359 ms
15,612 KB
testcase_19 AC 400 ms
24,192 KB
testcase_20 TLE -
testcase_21 AC 961 ms
19,916 KB
testcase_22 AC 1,904 ms
33,248 KB
testcase_23 AC 1,354 ms
36,572 KB
testcase_24 AC 1,413 ms
36,700 KB
testcase_25 AC 1,349 ms
37,376 KB
testcase_26 AC 1,433 ms
37,384 KB
testcase_27 AC 1,443 ms
36,404 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class SegmentTree
	def initialize(v)
		@n = 1
		while @n < v.length do
			@n *= 2
		end
		@node = Array.new(2*@n-1, 0)
		v.each_with_index{|x, i|
			@node[i+@n-1] = x
		}
		(@n-2).downto(0) {|i|
			@node[i] = @node[2*i+1] ^ @node[2*i+2]
		}
	end
	def query(a, b, k=0, l=0, r=@n)
		if r <= a or b <= l then
			return 0
		end
		if a <= l and r <= b then
			return @node[k]
		else
			vl = query(a, b, k * 2 + 1, l, (l + r) / 2)
			vr = query(a, b, k * 2 + 2, (l + r) / 2, r)
			return vl ^ vr
		end
	end
end

N, Q = gets.split(" ").map{|s| s.to_i}
a = gets.split(" ").map{|s| s.to_i}

q = []
Q.times {
	q << gets.split(" ").map(&:to_i)
}

st = SegmentTree.new(a)

ans = []

q.each {|l, r|
	ans << st.query(l-1, r)
}

puts ans
0