提出 #48153886


ソースコード 拡げる

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

N,Q = gets.split.map(&:to_i)
S = gets.chomp.bytes
T = S.reverse
P = 2**29+11
Op1 = lambda{|b0|
	*pb = b = 1
	N.times{
		pb<<b = b*b0%P
	}
	lambda{|cl,cr,(sl,sr)|
		(sl+pb[cl]*sr)%P
	}
}[10**9+7]
S1 = ST.new S,0,&Op1
T1 = ST.new T,0,&Op1
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

提出情報

提出日時
問題 F - Palindrome Query
ユーザ ds14050
言語 Ruby (ruby 3.2.2)
得点 525
コード長 1130 Byte
結果 AC
実行時間 1164 ms
メモリ 87820 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 525 / 525
結果
AC × 1
AC × 25
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 44 ms 17408 KiB
01_n_small_00.txt AC 241 ms 20884 KiB
01_n_small_01.txt AC 191 ms 21100 KiB
01_n_small_02.txt AC 246 ms 21012 KiB
01_n_small_03.txt AC 190 ms 21020 KiB
02_random_1_00.txt AC 1116 ms 84060 KiB
02_random_1_01.txt AC 1111 ms 84144 KiB
02_random_1_02.txt AC 1106 ms 84060 KiB
03_random_2_00.txt AC 1012 ms 82500 KiB
03_random_2_01.txt AC 989 ms 82620 KiB
03_random_2_02.txt AC 983 ms 82624 KiB
04_random_3_00.txt AC 1164 ms 86648 KiB
04_random_3_01.txt AC 1151 ms 86972 KiB
04_random_3_02.txt AC 1153 ms 86844 KiB
05_random_4_00.txt AC 878 ms 82716 KiB
05_random_4_01.txt AC 873 ms 82660 KiB
05_random_4_02.txt AC 930 ms 82616 KiB
06_corner_00.txt AC 1156 ms 86736 KiB
06_corner_01.txt AC 1163 ms 87820 KiB
06_corner_02.txt AC 1159 ms 86776 KiB
07_min_00.txt AC 43 ms 17176 KiB
08_hack_00.txt AC 877 ms 82692 KiB
08_hack_01.txt AC 891 ms 82716 KiB
08_hack_02.txt AC 869 ms 82500 KiB
08_hack_03.txt AC 1064 ms 83256 KiB