結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
12,288 KB
testcase_01 AC 86 ms
12,160 KB
testcase_02 AC 82 ms
12,160 KB
testcase_03 AC 233 ms
24,448 KB
testcase_04 AC 676 ms
23,640 KB
testcase_05 AC 779 ms
31,444 KB
testcase_06 AC 106 ms
14,720 KB
testcase_07 AC 789 ms
25,676 KB
testcase_08 AC 1,099 ms
31,064 KB
testcase_09 AC 565 ms
21,228 KB
testcase_10 AC 786 ms
29,432 KB
testcase_11 AC 1,000 ms
30,312 KB
testcase_12 AC 600 ms
31,448 KB
testcase_13 AC 1,143 ms
31,176 KB
testcase_14 AC 845 ms
29,556 KB
testcase_15 AC 903 ms
31,436 KB
testcase_16 AC 859 ms
27,120 KB
testcase_17 AC 1,164 ms
33,868 KB
testcase_18 AC 243 ms
15,572 KB
testcase_19 AC 281 ms
24,320 KB
testcase_20 AC 1,106 ms
31,232 KB
testcase_21 AC 547 ms
20,096 KB
testcase_22 AC 1,050 ms
33,112 KB
testcase_23 AC 1,190 ms
37,380 KB
testcase_24 AC 1,194 ms
37,384 KB
testcase_25 AC 1,192 ms
37,256 KB
testcase_26 AC 1,191 ms
36,548 KB
testcase_27 AC 1,259 ms
37,256 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class SegmentTree
	def initialize(v)
		@n = 1
		while @n < v.length do
			@n *= 2
		end
		@node = Array.new(2*@n, 0)
		v.each_with_index{|x, i|
			@node[i+@n] = x
		}
		(@n-1).downto(1) {|i|
			@node[i] = @node[2*i] ^ @node[2*i+1]
		}
	end
	def query(l, r)
		l += @n
		r += @n
		lres, rres = 0, 0
		while l < r do
			if l & 1 != 0 then
				lres ^= @node[l]
				l += 1
			end
			if r & 1 != 0 then
				r -= 1
				rres ^= @node[r]
			end
			l >>= 1
			r >>= 1
		end
		lres ^ rres
	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