Submission #43229224


Source Code Expand

class Stat
	def initialize m
		@m = m
		@x = {}
		@xs = {}
	end

	def conflict?
		! @xs.empty?
	end
	def each_pair &block
		Enumerator.new{|y|
			@xs.each_value{|xs|
				xs.keys.combination(2){|xx|
					y<<xx
				}
			}
		}.each(&block)
	end

	def put x
		pfx = @m&x
		if xs = @xs[pfx]
			xs[x] = x
		elsif y = @x[pfx] and x!=y
			@x.delete pfx
			@xs[pfx] = {x=>x, y=>y}
		else
			@x[pfx] = x
		end
	end
	def del x
		pfx = @m&x
		if xs = @xs[pfx]
			xs.delete x
			y, = xs.shift if xs.size==1
			@xs.delete pfx if xs.empty?
			@x[pfx] = y if y
		elsif @x[pfx]==x
			@x.delete pfx
		else
			# put してない x を del しようとした。
		end
	end
end

A = []
S = [Stat.new(m = (1<<30)-1)]
S.push Stat.new m &= m-1 while 0<m
X = Hash.new xx = 0
gets.to_i.times{
	c,x = gets.split.map(&:to_i)
	case c
	when 1
		xx += 1 if 2==X[x] += 1
		S.each{|st| st.put x } if 1==X[x]
	when 2
		xx -= 1 if 1==X[x] -= 1
		S.each{|st| st.del x } if 0==X[x]
	else
		A.push 0<xx ? 0 : S.find(&:conflict?).each_pair.map{_1^_2}.min
	end
}

puts A

Submission Info

Submission Time
Task G - Minimum Xor Pair Query
User ds14050
Language Ruby (2.7.1)
Score 0
Code Size 1096 Byte
Status TLE
Exec Time 3319 ms
Memory 265392 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 600
Status
AC × 1
AC × 11
TLE × 14
Set Name Test Cases
Sample 00_sample_01.txt
All 00_sample_01.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 60 ms 14312 KiB
01_test_01.txt TLE 3318 ms 257708 KiB
01_test_02.txt TLE 3318 ms 255724 KiB
01_test_03.txt TLE 3319 ms 257592 KiB
01_test_04.txt TLE 3317 ms 222612 KiB
01_test_05.txt TLE 3317 ms 219572 KiB
01_test_06.txt TLE 3317 ms 221328 KiB
01_test_07.txt TLE 3317 ms 220252 KiB
01_test_08.txt TLE 3317 ms 217880 KiB
01_test_09.txt AC 1982 ms 20632 KiB
01_test_10.txt AC 1995 ms 20472 KiB
01_test_11.txt AC 2075 ms 20612 KiB
01_test_12.txt AC 2090 ms 20760 KiB
01_test_13.txt AC 2582 ms 21892 KiB
01_test_14.txt AC 2566 ms 22268 KiB
01_test_15.txt AC 2986 ms 37636 KiB
01_test_16.txt AC 2959 ms 38000 KiB
01_test_17.txt AC 323 ms 15532 KiB
01_test_18.txt TLE 3319 ms 265392 KiB
01_test_19.txt TLE 3319 ms 265232 KiB
01_test_20.txt TLE 3318 ms 241532 KiB
01_test_21.txt TLE 3318 ms 241208 KiB
01_test_22.txt TLE 3318 ms 242164 KiB
01_test_23.txt TLE 3318 ms 241220 KiB
01_test_24.txt AC 1394 ms 14204 KiB