Submission #65275305


Source Code Expand

class BIT
	def initialize n
		@a = [0]*(n+1) # 1-indexed internally
	end

	def [] i
		i += 1
		s = 0
		while 0<i
			s += @a[i]
			i &= i-1
		end
		return s
	end
	def lb s
		z = @a.size-1
		i,t,b = 0,0,1<<z.bit_length
		t += @a[i|=b] if i|b<=z && t+@a[i|b]<s while 0<b >>= 1
		return i # i は1大きい内部インデックス(もしくは 0)だけど、求めた添字が s より小さい値を返す最大の添字であり、s 以上を返す最小の添字としては +1 したものを返したいから、足し引きして内部インデックスそのままの値を返す(アクセス可能な範囲を1超えることがあります。サイズに等しい値)。
	end
 
	def add i,d
		i += 1
		while i<@a.size
			@a[i] += d
			i += i&-i
		end
	end
	def inc i; add i,1 end
	def dec i; add i,-1 end
end

Qry = gets.to_i.times.map{ gets.split }
Xs,Ys = [],[]
Qry.each{|t,s|
	(t==?1 ? Xs : Ys)<<s
}
Xs.sort!.uniq!
Ys.sort!.uniq!
X2I = Xs.each_with_index.to_h
Y2I = Ys.each_with_index.to_h

D = [nil]*X2I.size # X がどの Y を除外するか
Xs.each_with_index{|x,i|
	j = Ys.bsearch_index{|y| x<=y }
	if j && Ys[j].start_with?(x)
		k = (j...Ys.size).bsearch{|k|
			! Ys[k].start_with?(x)
		}||Ys.size
		D[i] = j...k
	end
}

DeletedY = BIT.new Ys.size+1
UndeletedY = BIT.new Ys.size+1
puts Qry.map{|t,s|
	case t
	when ?1
		i = X2I[s]
		if r = D[i]
			DeletedY.inc r.begin
			DeletedY.dec r.end
			v = r.begin==0 ? 1 : UndeletedY[r.begin-1]+1
			while (j = UndeletedY.lb v) and j<r.end
				UndeletedY.dec j
			end
		end
	when ?2
		i = Y2I[s]
		if 0<DeletedY[i]
		else
			UndeletedY.inc i
		end
	end
	UndeletedY[Ys.size]
}

Submission Info

Submission Time
Task E - Forbidden Prefix
User ds14050
Language Ruby (ruby 3.2.2)
Score 500
Code Size 1711 Byte
Status AC
Exec Time 578 ms
Memory 67256 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 57
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt
All 00_sample_01.txt, 00_sample_02.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt, 02_handmade_06.txt, 02_handmade_07.txt, 02_handmade_08.txt, 02_handmade_09.txt, 02_handmade_10.txt, 02_handmade_11.txt, 02_handmade_12.txt, 02_handmade_13.txt, 02_handmade_14.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 43 ms 17184 KiB
00_sample_02.txt AC 43 ms 17256 KiB
01_random_01.txt AC 45 ms 18460 KiB
01_random_02.txt AC 45 ms 18216 KiB
01_random_03.txt AC 46 ms 18148 KiB
01_random_04.txt AC 46 ms 18452 KiB
01_random_05.txt AC 45 ms 18372 KiB
01_random_06.txt AC 44 ms 18388 KiB
01_random_07.txt AC 48 ms 18452 KiB
01_random_08.txt AC 56 ms 18856 KiB
01_random_09.txt AC 70 ms 20680 KiB
01_random_10.txt AC 67 ms 19972 KiB
01_random_11.txt AC 55 ms 18784 KiB
01_random_12.txt AC 56 ms 19756 KiB
01_random_13.txt AC 58 ms 19896 KiB
01_random_14.txt AC 519 ms 67068 KiB
01_random_15.txt AC 555 ms 67256 KiB
01_random_16.txt AC 578 ms 66964 KiB
01_random_17.txt AC 344 ms 47836 KiB
01_random_18.txt AC 416 ms 66616 KiB
01_random_19.txt AC 46 ms 18540 KiB
01_random_20.txt AC 45 ms 18492 KiB
01_random_21.txt AC 122 ms 24484 KiB
01_random_22.txt AC 50 ms 18568 KiB
01_random_23.txt AC 137 ms 27036 KiB
01_random_24.txt AC 511 ms 60780 KiB
01_random_25.txt AC 357 ms 52932 KiB
01_random_26.txt AC 388 ms 56400 KiB
01_random_27.txt AC 225 ms 40780 KiB
01_random_28.txt AC 517 ms 57440 KiB
01_random_29.txt AC 351 ms 46088 KiB
01_random_30.txt AC 410 ms 57044 KiB
01_random_31.txt AC 286 ms 43204 KiB
01_random_32.txt AC 333 ms 48684 KiB
01_random_33.txt AC 137 ms 28572 KiB
01_random_34.txt AC 437 ms 56744 KiB
01_random_35.txt AC 345 ms 48780 KiB
01_random_36.txt AC 367 ms 55964 KiB
01_random_37.txt AC 471 ms 53336 KiB
01_random_38.txt AC 431 ms 59484 KiB
01_random_39.txt AC 352 ms 49436 KiB
01_random_40.txt AC 290 ms 46416 KiB
01_random_41.txt AC 258 ms 43440 KiB
02_handmade_01.txt AC 44 ms 18628 KiB
02_handmade_02.txt AC 44 ms 18452 KiB
02_handmade_03.txt AC 336 ms 59352 KiB
02_handmade_04.txt AC 355 ms 59304 KiB
02_handmade_05.txt AC 72 ms 21664 KiB
02_handmade_06.txt AC 76 ms 21692 KiB
02_handmade_07.txt AC 49 ms 18668 KiB
02_handmade_08.txt AC 49 ms 18616 KiB
02_handmade_09.txt AC 46 ms 18460 KiB
02_handmade_10.txt AC 47 ms 18104 KiB
02_handmade_11.txt AC 43 ms 18248 KiB
02_handmade_12.txt AC 44 ms 18288 KiB
02_handmade_13.txt AC 44 ms 18220 KiB
02_handmade_14.txt AC 44 ms 17856 KiB