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