Submission #48153685


Source Code Expand

Copy
class ST
def initialize a,e,&op
@l = (1<<(a.size-1).bit_length)
@a = [e]*@l+a
@a<<e
@op = op
c,l = 1,@l>>1
((@l+a.size-1)/2).downto(1){|i|
c,l = c<<1,l>>1 if i<l
@a[i] = @op[c,c,@a[i+i,2]]
}
end
def [] l,r
return if r<l
l,r,c = l+@l,r+@l,1
cl,al = 1,@a[l]
cr,ar = 1,@a[r]
while l+1<r
cl,al = cl+c,@op[cl,c,[al,@a[l+1]]] if l&1<1
cr,ar = c+cr,@op[c,cr,[@a[r-1],ar]] if 0<r&1
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
class ST
	def initialize a,e,&op
		@l = (1<<(a.size-1).bit_length)
		@a = [e]*@l+a
		@a<<e
		@op = op
		c,l = 1,@l>>1
		((@l+a.size-1)/2).downto(1){|i|
			c,l = c<<1,l>>1 if i<l
			@a[i] = @op[c,c,@a[i+i,2]]
		}
	end

	def [] l,r
		return if r<l
		l,r,c = l+@l,r+@l,1
		cl,al = 1,@a[l]
		cr,ar = 1,@a[r]
		while l+1<r
			cl,al = cl+c,@op[cl,c,[al,@a[l+1]]] if l&1<1
			cr,ar = c+cr,@op[c,cr,[@a[r-1],ar]] if 0<r&1
			l,r,c = l/2,r/2,c*2
		end
		return l==r ? al : @op[cl,cr,[al,ar]]
	end

	def []= i,v
		i += @l
		@a[i] = v
		c = 1
		@a[i],c = @op[c,c,@a[i+i,2]],c*2 while 0<i/=2
		return v
	end
end
P = 2**50+55
Op = lambda{|b|
	lambda{|cl,cr,(sl,sr)|
		(sl+b.pow(cl,P)*sr)%P
	}
}

N,Q = gets.split.map(&:to_i)
S = gets.chomp.bytes
T = S.reverse
S1 = ST.new S,0,&Op[10**9+7]
T1 = ST.new T,0,&Op[10**9+7]
A = []
Q.times{
	q,a1,a2 = gets.split
	case q.to_i
	when 1
		x,c = a1.to_i-1,a2.ord
		rx = N-1-x
		S1[x] = T1[rx] = c
	when 2
		l,r = a1.to_i-1,a2.to_i-1
		rl,rr = N-1-r,N-1-l
		A<<(S1[l,r]==T1[rl,rr]?'Yes':'No')
	end
}
puts A

Submission Info

Submission Time
Task F - Palindrome Query
User ds14050
Language Ruby (ruby 3.2.2)
Score 0
Code Size 1093 Byte
Status TLE
Exec Time 3318 ms
Memory 79020 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 525
Status
AC × 1
AC × 15
TLE × 10
Set Name Test Cases
Sample 00_sample_00.txt
All 00_sample_00.txt, 01_n_small_00.txt, 01_n_small_01.txt, 01_n_small_02.txt, 01_n_small_03.txt, 02_random_1_00.txt, 02_random_1_01.txt, 02_random_1_02.txt, 03_random_2_00.txt, 03_random_2_01.txt, 03_random_2_02.txt, 04_random_3_00.txt, 04_random_3_01.txt, 04_random_3_02.txt, 05_random_4_00.txt, 05_random_4_01.txt, 05_random_4_02.txt, 06_corner_00.txt, 06_corner_01.txt, 06_corner_02.txt, 07_min_00.txt, 08_hack_00.txt, 08_hack_01.txt, 08_hack_02.txt, 08_hack_03.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 48 ms 17260 KB
01_n_small_00.txt AC 480 ms 20936 KB
01_n_small_01.txt AC 279 ms 21060 KB
01_n_small_02.txt AC 490 ms 20832 KB
01_n_small_03.txt AC 270 ms 20992 KB
02_random_1_00.txt TLE 3128 ms 76168 KB
02_random_1_01.txt TLE 3141 ms 76168 KB
02_random_1_02.txt TLE 3168 ms 76188 KB
03_random_2_00.txt AC 2665 ms 74684 KB
03_random_2_01.txt AC 2676 ms 74780 KB
03_random_2_02.txt AC 2638 ms 74596 KB
04_random_3_00.txt TLE 3315 ms 78856 KB
04_random_3_01.txt TLE 3318 ms 79020 KB
04_random_3_02.txt TLE 3318 ms 78856 KB
05_random_4_00.txt AC 2430 ms 74700 KB
05_random_4_01.txt AC 2429 ms 74896 KB
05_random_4_02.txt AC 2429 ms 74752 KB
06_corner_00.txt TLE 3315 ms 78896 KB
06_corner_01.txt TLE 3315 ms 79020 KB
06_corner_02.txt TLE 3315 ms 77476 KB
07_min_00.txt AC 49 ms 17192 KB
08_hack_00.txt AC 2445 ms 74860 KB
08_hack_01.txt AC 2448 ms 74768 KB
08_hack_02.txt AC 2435 ms 74872 KB
08_hack_03.txt TLE 3256 ms 75388 KB


2025-04-08 (Tue)
14:02:25 +00:00