Please sign in first.
Submission #53068475
Source Code Expand
import sys input = sys.stdin.readline from collections import defaultdict def add(i: int) -> None: global danger for k, v in new_factor[i]: num[k] += v if num[k] % 3 != 0 and ((num[k] - v) % 3 == 0): danger += 1 if num[k] % 3 == 0 and ((num[k] - v) % 3 != 0): danger -= 1 def delete(i: int) -> None: global danger for k, v in new_factor[i]: num[k] -= v if num[k] % 3 == 0 and ((num[k] + v) % 3 != 0): danger -= 1 if num[k] % 3 != 0 and ((num[k] + v) % 3 == 0): danger += 1 def Eratosthenes() -> None: n = max(A) primes = [True] * (n + 1) primes[0] = False primes[1] = False for i in range(2, n + 1): if primes[i]: min_fac[i] = i for j in range(2 * i, n + 1, i): primes[j] = False if min_fac[j] == -1: min_fac[j] = i def Factorization() -> None: for i in range(N): now = A[i] while True: if now == 1: break if min_fac[now] == now: factor[i].append(now) break else: factor[i].append(min_fac[now]) now //= min_fac[now] def main() -> None: global N, Q, A, min_fac, factor, num, danger, new_factor N, Q = map(int, input().split()) A = list(map(int, input().split())) block = int(N / Q ** 0.5) + 1 queries = [[] for _ in range(int(Q**0.5) + 1)] for i in range(Q): L, R = map(lambda x: int(x) - 1, input().split()) queries[L // block].append((i, L, R)) min_fac = [-1] * (max(A) + 1) # min_fac[i] := i の最小の素因数 factor = [[] for _ in range(N)] # factor[i] := A[i] の素因数分解 # S[i][r] - S[i][l - 1] := [l, r] の i の素因数の個数 Eratosthenes() Factorization() # print(min_fac[:30]) # print(*factor[:30], sep="\n") new_factor = [[] for _ in range(N)] for i in range(N): d = defaultdict(int) for j in factor[i]: d[j] += 1 for k, v in d.items(): new_factor[i].append((k, v)) # print(*new_factor, sep="\n") ans = [0] * Q left, right = 0, 0 num = [0] * (max(A) + 1) # num[i] := [l, r] の中にある素因数 i の合計 danger = 0 # danger >= 1 := 3 の倍数個でない素因数が存在する for ind, query in enumerate(queries): for i, l, r in sorted(query, reverse=ind%2, key=lambda x: x[2]): while right <= r: add(right) right += 1 while l < left: left -= 1 add(left) while r + 1 < right: right -= 1 delete(right) while left < l: delete(left) left += 1 ans[i] = (danger == 0) for i in range(Q): print("Yes") if ans[i] else print("No") if __name__ == "__main__": main()
Submission Info
Submission Time | |
---|---|
Task | G - Cubic? |
User | ryusuke_h |
Language | Python (PyPy 3.10-v7.3.12) |
Score | 0 |
Code Size | 3150 Byte |
Status | TLE |
Exec Time | 3322 ms |
Memory | 220068 KiB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 600 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample_01.txt |
All | sample_01.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt, test_35.txt, test_36.txt, test_37.txt, test_38.txt, test_39.txt, test_40.txt, test_41.txt, test_42.txt, test_43.txt, test_44.txt, test_45.txt, test_46.txt, test_47.txt, test_48.txt, test_49.txt, test_50.txt, test_51.txt, test_52.txt, test_53.txt, test_54.txt, test_55.txt, test_56.txt, test_57.txt, test_58.txt, test_59.txt, test_60.txt, test_61.txt, test_62.txt, test_63.txt, test_64.txt, test_65.txt, test_66.txt, test_67.txt, test_68.txt, test_69.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
sample_01.txt | AC | 75 ms | 76968 KiB |
test_01.txt | AC | 102 ms | 95452 KiB |
test_02.txt | TLE | 3318 ms | 152328 KiB |
test_03.txt | AC | 580 ms | 110860 KiB |
test_04.txt | AC | 2413 ms | 140200 KiB |
test_05.txt | TLE | 3322 ms | 167664 KiB |
test_06.txt | AC | 461 ms | 118284 KiB |
test_07.txt | AC | 1467 ms | 127024 KiB |
test_08.txt | TLE | 3322 ms | 171760 KiB |
test_09.txt | AC | 371 ms | 106372 KiB |
test_10.txt | AC | 1881 ms | 155564 KiB |
test_11.txt | TLE | 3319 ms | 167748 KiB |
test_12.txt | AC | 2106 ms | 145900 KiB |
test_13.txt | AC | 1318 ms | 139708 KiB |
test_14.txt | TLE | 3320 ms | 182284 KiB |
test_15.txt | AC | 2365 ms | 140100 KiB |
test_16.txt | AC | 2922 ms | 157664 KiB |
test_17.txt | AC | 2277 ms | 136680 KiB |
test_18.txt | AC | 408 ms | 126180 KiB |
test_19.txt | AC | 2386 ms | 145372 KiB |
test_20.txt | AC | 1454 ms | 108708 KiB |
test_21.txt | TLE | 3318 ms | 155396 KiB |
test_22.txt | TLE | 3320 ms | 190708 KiB |
test_23.txt | TLE | 3320 ms | 190720 KiB |
test_24.txt | TLE | 3319 ms | 181000 KiB |
test_25.txt | TLE | 3319 ms | 168688 KiB |
test_26.txt | TLE | 3319 ms | 173440 KiB |
test_27.txt | TLE | 3321 ms | 163864 KiB |
test_28.txt | TLE | 3318 ms | 164916 KiB |
test_29.txt | TLE | 3319 ms | 174564 KiB |
test_30.txt | TLE | 3319 ms | 174536 KiB |
test_31.txt | TLE | 3319 ms | 184032 KiB |
test_32.txt | TLE | 3319 ms | 173836 KiB |
test_33.txt | TLE | 3320 ms | 198012 KiB |
test_34.txt | TLE | 3320 ms | 193720 KiB |
test_35.txt | TLE | 3320 ms | 193940 KiB |
test_36.txt | TLE | 3319 ms | 197928 KiB |
test_37.txt | TLE | 3321 ms | 208368 KiB |
test_38.txt | TLE | 3319 ms | 181160 KiB |
test_39.txt | AC | 384 ms | 137332 KiB |
test_40.txt | TLE | 3320 ms | 190908 KiB |
test_41.txt | TLE | 3321 ms | 211516 KiB |
test_42.txt | TLE | 3320 ms | 197812 KiB |
test_43.txt | TLE | 3321 ms | 207500 KiB |
test_44.txt | TLE | 3321 ms | 207564 KiB |
test_45.txt | TLE | 3319 ms | 171500 KiB |
test_46.txt | TLE | 3320 ms | 192492 KiB |
test_47.txt | TLE | 3321 ms | 208204 KiB |
test_48.txt | TLE | 3320 ms | 197752 KiB |
test_49.txt | TLE | 3321 ms | 207932 KiB |
test_50.txt | TLE | 3319 ms | 180332 KiB |
test_51.txt | TLE | 3320 ms | 197644 KiB |
test_52.txt | TLE | 3320 ms | 190932 KiB |
test_53.txt | TLE | 3321 ms | 208180 KiB |
test_54.txt | TLE | 3320 ms | 198168 KiB |
test_55.txt | TLE | 3321 ms | 207796 KiB |
test_56.txt | TLE | 3321 ms | 207492 KiB |
test_57.txt | TLE | 3321 ms | 220068 KiB |
test_58.txt | TLE | 3320 ms | 192484 KiB |
test_59.txt | TLE | 3321 ms | 208460 KiB |
test_60.txt | TLE | 3320 ms | 198576 KiB |
test_61.txt | TLE | 3321 ms | 207616 KiB |
test_62.txt | TLE | 3319 ms | 170440 KiB |
test_63.txt | TLE | 3320 ms | 206632 KiB |
test_64.txt | TLE | 3319 ms | 190928 KiB |
test_65.txt | TLE | 3321 ms | 208316 KiB |
test_66.txt | TLE | 3320 ms | 197896 KiB |
test_67.txt | TLE | 3321 ms | 207432 KiB |
test_68.txt | TLE | 3319 ms | 180928 KiB |
test_69.txt | TLE | 3321 ms | 213188 KiB |