結果
問題 | No.1746 Sqrt Integer Segments |
ユーザー | mkawa2 |
提出日時 | 2021-11-18 09:05:31 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 514 ms / 2,000 ms |
コード長 | 2,015 bytes |
コンパイル時間 | 450 ms |
コンパイル使用メモリ | 82,072 KB |
実行使用メモリ | 163,344 KB |
最終ジャッジ日時 | 2024-09-13 09:26:04 |
合計ジャッジ時間 | 11,855 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 117 ms
95,548 KB |
testcase_01 | AC | 113 ms
95,216 KB |
testcase_02 | AC | 399 ms
139,616 KB |
testcase_03 | AC | 287 ms
117,860 KB |
testcase_04 | AC | 333 ms
128,640 KB |
testcase_05 | AC | 507 ms
160,244 KB |
testcase_06 | AC | 255 ms
112,004 KB |
testcase_07 | AC | 184 ms
101,232 KB |
testcase_08 | AC | 396 ms
136,356 KB |
testcase_09 | AC | 510 ms
158,556 KB |
testcase_10 | AC | 247 ms
112,168 KB |
testcase_11 | AC | 472 ms
155,672 KB |
testcase_12 | AC | 508 ms
163,344 KB |
testcase_13 | AC | 513 ms
161,392 KB |
testcase_14 | AC | 514 ms
162,088 KB |
testcase_15 | AC | 500 ms
162,532 KB |
testcase_16 | AC | 497 ms
155,056 KB |
testcase_17 | AC | 355 ms
134,044 KB |
testcase_18 | AC | 154 ms
112,240 KB |
testcase_19 | AC | 155 ms
111,948 KB |
testcase_20 | AC | 155 ms
112,332 KB |
testcase_21 | AC | 196 ms
104,012 KB |
testcase_22 | AC | 198 ms
104,056 KB |
testcase_23 | AC | 167 ms
102,084 KB |
testcase_24 | AC | 270 ms
113,324 KB |
testcase_25 | AC | 269 ms
113,664 KB |
testcase_26 | AC | 269 ms
113,808 KB |
testcase_27 | AC | 412 ms
120,460 KB |
testcase_28 | AC | 409 ms
118,172 KB |
testcase_29 | AC | 407 ms
117,896 KB |
ソースコード
import sys sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = 18446744073709551615 # inf = 4294967295 md = 10**9+7 # md = 998244353 from random import randrange class Sieve: def __init__(self, n): self.plist = [2] # n以下の素数のリスト min_prime_factor = [2, 0]*(n//2+1) for x in range(3, n+1, 2): if min_prime_factor[x] == 0: min_prime_factor[x] = x self.plist.append(x) if x**2 > n: continue for y in range(x**2, n+1, 2*x): if min_prime_factor[y] == 0: min_prime_factor[y] = x self.min_prime_factor = min_prime_factor def isprime(self, x): return self.min_prime_factor[x] == x # これが素因数分解(prime factorization) def pfct(self, x): pp, ee = [], [] while x > 1: mpf = self.min_prime_factor[x] if pp and mpf == pp[-1]: ee[-1] += 1 else: pp.append(mpf) ee.append(1) x //= mpf return [(p, e) for p, e in zip(pp, ee)] from collections import Counter n = II() aa = LI() sv = Sieve(1000005) enc = {p: randrange(inf) for p in sv.plist} ss = [] ans = 0 for a in aa: pe = sv.pfct(a) cur = 0 for p, e in pe: if e & 1: cur ^= enc[p] ss.append(cur) cnt = Counter() cnt[0] = 1 ans = 0 x = 0 for s in ss: x ^= s ans += cnt[x] cnt[x] += 1 print(ans)