Submission #17400113


Source Code Expand

Copy
class BIT
def initialize n
@a = [0]*n
end
def [] i
i += 1
s = 0
while 0 < i
s += @a[i-1]
i -= i&-i
end
return s
end
def inc i
i += 1
until @a.size < i
@a[i-1] += 1
i += i&-i
end
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
class BIT
	def initialize n
		@a = [0]*n
	end
 
	def [] i
		i += 1
		s = 0
		while 0 < i
			s += @a[i-1]
			i -= i&-i
		end
		return s
	end
 
	def inc i
		i += 1
		until @a.size < i
			@a[i-1] += 1
			i += i&-i
		end
	end
end

(N,Q),C,*LR = $<.map{|ln| ln.split.map(&:to_i) }

LR.map!.with_index{|(l,r),q| [r-1,l-1,q] }.sort_by!{|r,| r }

A = [0]*Q     # answer
LOC = [nil]*N # last occurrence of colors
COL = BIT.new N
C.each_with_index{|c,i|
	COL.inc N-1-LOC[-c] if LOC[-c]
	LOC[-c] = i
	while LR[0][0] == i
		_,l,q = LR.shift
		A[q] = i-l+1-COL[N-1-l]
	end rescue break
}
puts A

Submission Info

Submission Time
Task F - Range Set Query
User ds14050
Language Ruby (2.7.1)
Score 0
Code Size 622 Byte
Status TLE
Exec Time 2060 ms
Memory 108324 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 600
Status
AC × 2
AC × 6
TLE × 1
Set Name Test Cases
Sample sample00, sample01
All handmade02, handmade03, handmade04, handmade05, random06, sample00, sample01
Case Name Status Exec Time Memory
handmade02 AC 59 ms 14056 KB
handmade03 AC 410 ms 28468 KB
handmade04 AC 1791 ms 108324 KB
handmade05 TLE 2060 ms 108248 KB
random06 AC 1907 ms 107348 KB
sample00 AC 59 ms 14176 KB
sample01 AC 58 ms 14252 KB


2025-04-20 (Sun)
13:33:35 +00:00