結果

問題 No.854 公平なりんご分配
ユーザー 双六双六
提出日時 2020-08-12 02:21:26
言語 PyPy3
(7.3.13)
結果
TLE  
実行時間 -
コード長 2,090 bytes
コンパイル時間 327 ms
コンパイル使用メモリ 86,508 KB
実行使用メモリ 191,800 KB
最終ジャッジ日時 2023-07-30 17:15:24
合計ジャッジ時間 16,675 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
191,800 KB
testcase_01 AC 110 ms
78,224 KB
testcase_02 AC 112 ms
78,048 KB
testcase_03 AC 112 ms
78,156 KB
testcase_04 AC 111 ms
77,820 KB
testcase_05 AC 113 ms
77,624 KB
testcase_06 AC 108 ms
77,852 KB
testcase_07 AC 109 ms
77,960 KB
testcase_08 AC 109 ms
77,960 KB
testcase_09 AC 112 ms
77,636 KB
testcase_10 AC 112 ms
77,920 KB
testcase_11 AC 112 ms
77,924 KB
testcase_12 AC 114 ms
78,188 KB
testcase_13 AC 115 ms
78,104 KB
testcase_14 AC 113 ms
77,620 KB
testcase_15 AC 111 ms
77,852 KB
testcase_16 AC 113 ms
77,960 KB
testcase_17 AC 112 ms
77,892 KB
testcase_18 AC 112 ms
78,088 KB
testcase_19 AC 112 ms
78,180 KB
testcase_20 AC 111 ms
78,072 KB
testcase_21 AC 114 ms
77,620 KB
testcase_22 AC 307 ms
79,940 KB
testcase_23 AC 205 ms
79,968 KB
testcase_24 AC 374 ms
81,752 KB
testcase_25 AC 194 ms
79,928 KB
testcase_26 AC 383 ms
81,480 KB
testcase_27 AC 242 ms
80,264 KB
testcase_28 AC 303 ms
79,280 KB
testcase_29 AC 160 ms
78,304 KB
testcase_30 AC 229 ms
80,328 KB
testcase_31 AC 364 ms
80,864 KB
testcase_32 AC 1,417 ms
103,328 KB
testcase_33 TLE -
testcase_34 TLE -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
testcase_73 -- -
testcase_74 -- -
testcase_75 -- -
testcase_76 -- -
testcase_77 -- -
testcase_78 -- -
testcase_79 -- -
testcase_80 -- -
testcase_81 -- -
testcase_82 -- -
testcase_83 -- -
testcase_84 -- -
testcase_85 -- -
testcase_86 -- -
testcase_87 -- -
testcase_88 -- -
testcase_89 -- -
testcase_90 -- -
testcase_91 -- -
testcase_92 -- -
testcase_93 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

num = 51
L = [1 for i in range(num)]; L[0] = 0; L[1] = 0
plist = []
for i in range(num):
	if L[i] == 1:
		plist.append(i); c = 2
		while i * c <= num - 1:
			L[i * c] = 0; c += 1

def prime_factorization(N):
	D = defaultdict(int)
	for i in plist:
		while N % i == 0:
			D[i] += 1; N = int(N // i)

	if N != 1:
		D[N] += 1

	return D

num = 10 ** 5
L = [1 for i in range(num)]; L[0] = 0; L[1] = 0
plist2 = []
for i in range(num):
	if L[i] == 1:
		plist2.append(i); c = 2
		while i * c <= num - 1:
			L[i * c] = 0; c += 1

def prime_factorization_Q(N):
	D = defaultdict(int)
	for i in plist2:
		while N % i == 0:
			D[i] += 1; N = int(N // i)

	if N != 1:
		D[N] += 1

	return D

def getlist():
	return list(map(int, input().split()))

class SegmentTree(object):
	def __init__(self, N):
		self.N = N
		self.N0 = 2 ** (N - 1).bit_length()
		self.initVal = defaultdict(int)
		self.data = [self.initVal] * (2 * self.N0)

	def calc(self, a, b):
		d = defaultdict(int)
		for i in a:
			d[i] += a[i]
		for i in b:
			d[i] += b[i]

		return d

	def initialize(self, A):
		for i in range(self.N):
			self.data[self.N0 - 1 + i] = A[i]
		for i in range(self.N0 - 2, -1, -1):
			self.data[i] = self.calc(self.data[2 * i + 1], self.data[2 * i + 2])

	def query(self, l, r):
		L = l + self.N0; R = r + self.N0 + 1
		m = self.initVal
		while L < R:
			if R & 1:
				R -= 1
				m = self.calc(m, self.data[R - 1])
			if L & 1:
				m = self.calc(m, self.data[L - 1])
				L += 1
			L >>= 1; R >>= 1

		return m

#処理内容
def main():
	N = int(input())
	A = getlist()
	B = [prime_factorization(i) for i in A]
	Seg = SegmentTree(N)
	Seg.initialize(B)

	Q = int(input())
	for i in range(Q):
		P, L, R = getlist()
		Pfac = prime_factorization_Q(P)
		L -= 1; R -= 1
		crossD = Seg.query(L, R)

		jud = 1
		for x in Pfac:
			if crossD[x] < Pfac[x]:
				jud = 0
				break

		if jud == 1:
			print("Yes")
		else:
			print("NO")


if __name__ == '__main__':
	main()
0