結果

問題 No.1091 Range Xor Query
ユーザー 小野寺健小野寺健
提出日時 2021-11-05 13:21:23
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,924 ms / 2,000 ms
コード長 704 bytes
コンパイル時間 147 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 35,876 KB
最終ジャッジ日時 2024-04-23 20:50:29
合計ジャッジ時間 33,727 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
12,160 KB
testcase_01 AC 73 ms
12,160 KB
testcase_02 AC 77 ms
12,160 KB
testcase_03 AC 264 ms
24,320 KB
testcase_04 AC 1,110 ms
22,612 KB
testcase_05 AC 1,243 ms
31,736 KB
testcase_06 AC 100 ms
14,592 KB
testcase_07 AC 1,265 ms
24,432 KB
testcase_08 AC 1,802 ms
29,796 KB
testcase_09 AC 884 ms
20,328 KB
testcase_10 AC 1,224 ms
28,256 KB
testcase_11 AC 1,669 ms
29,644 KB
testcase_12 AC 944 ms
31,308 KB
testcase_13 AC 1,924 ms
29,560 KB
testcase_14 AC 1,401 ms
28,236 KB
testcase_15 AC 1,465 ms
30,972 KB
testcase_16 AC 1,378 ms
25,928 KB
testcase_17 AC 1,912 ms
32,636 KB
testcase_18 AC 325 ms
15,360 KB
testcase_19 AC 361 ms
24,064 KB
testcase_20 AC 1,866 ms
29,772 KB
testcase_21 AC 857 ms
18,816 KB
testcase_22 AC 1,742 ms
31,960 KB
testcase_23 AC 1,275 ms
34,872 KB
testcase_24 AC 1,274 ms
35,848 KB
testcase_25 AC 1,269 ms
34,880 KB
testcase_26 AC 1,247 ms
35,844 KB
testcase_27 AC 1,258 ms
35,876 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{|s| s.to_i}
}

st = SegmentTree.new(a)

q.each {|l, r|
	puts st.query(l-1, r)
}
0