結果
| 問題 |
No.854 公平なりんご分配
|
| コンテスト | |
| ユーザー |
双六
|
| 提出日時 | 2020-08-12 02:21:26 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,090 bytes |
| コンパイル時間 | 171 ms |
| コンパイル使用メモリ | 82,796 KB |
| 実行使用メモリ | 120,892 KB |
| 最終ジャッジ日時 | 2024-10-09 12:26:26 |
| 合計ジャッジ時間 | 13,875 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 31 TLE * 2 -- * 59 |
ソースコード
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()
双六