結果
問題 | No.1365 [Cherry 1st Tune] Whose Fault? |
ユーザー | Navier_Boltzmann |
提出日時 | 2024-07-06 18:27:29 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 790 ms / 2,000 ms |
コード長 | 2,403 bytes |
コンパイル時間 | 240 ms |
コンパイル使用メモリ | 82,584 KB |
実行使用メモリ | 108,556 KB |
最終ジャッジ日時 | 2024-07-06 18:28:01 |
合計ジャッジ時間 | 29,760 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
55,552 KB |
testcase_01 | AC | 46 ms
55,680 KB |
testcase_02 | AC | 43 ms
55,680 KB |
testcase_03 | AC | 43 ms
56,704 KB |
testcase_04 | AC | 44 ms
56,704 KB |
testcase_05 | AC | 43 ms
56,832 KB |
testcase_06 | AC | 43 ms
56,936 KB |
testcase_07 | AC | 47 ms
62,080 KB |
testcase_08 | AC | 45 ms
57,268 KB |
testcase_09 | AC | 41 ms
56,192 KB |
testcase_10 | AC | 43 ms
56,448 KB |
testcase_11 | AC | 44 ms
55,936 KB |
testcase_12 | AC | 44 ms
56,960 KB |
testcase_13 | AC | 238 ms
80,584 KB |
testcase_14 | AC | 278 ms
79,984 KB |
testcase_15 | AC | 109 ms
78,208 KB |
testcase_16 | AC | 71 ms
77,284 KB |
testcase_17 | AC | 226 ms
79,424 KB |
testcase_18 | AC | 158 ms
78,840 KB |
testcase_19 | AC | 282 ms
80,392 KB |
testcase_20 | AC | 138 ms
77,824 KB |
testcase_21 | AC | 251 ms
80,324 KB |
testcase_22 | AC | 209 ms
79,424 KB |
testcase_23 | AC | 376 ms
91,392 KB |
testcase_24 | AC | 513 ms
91,412 KB |
testcase_25 | AC | 721 ms
93,992 KB |
testcase_26 | AC | 638 ms
93,084 KB |
testcase_27 | AC | 595 ms
85,888 KB |
testcase_28 | AC | 365 ms
81,392 KB |
testcase_29 | AC | 397 ms
84,576 KB |
testcase_30 | AC | 790 ms
96,012 KB |
testcase_31 | AC | 779 ms
99,076 KB |
testcase_32 | AC | 656 ms
96,920 KB |
testcase_33 | AC | 635 ms
90,920 KB |
testcase_34 | AC | 587 ms
90,752 KB |
testcase_35 | AC | 614 ms
92,240 KB |
testcase_36 | AC | 733 ms
99,504 KB |
testcase_37 | AC | 341 ms
83,572 KB |
testcase_38 | AC | 314 ms
93,404 KB |
testcase_39 | AC | 756 ms
92,124 KB |
testcase_40 | AC | 725 ms
91,588 KB |
testcase_41 | AC | 709 ms
96,236 KB |
testcase_42 | AC | 582 ms
84,480 KB |
testcase_43 | AC | 42 ms
56,064 KB |
testcase_44 | AC | 182 ms
108,556 KB |
testcase_45 | AC | 370 ms
77,132 KB |
ソースコード
# import pypyjit # pypyjit.set_param("max_unroll_recursion=-1") from collections import * from functools import * from itertools import * from heapq import * import sys, math # sys.setrecursionlimit(10**4) input = sys.stdin.readline class DSU: def __init__(self, n , B, P, A): self._n = n self.parent_or_size = [-1] * n self.P = P self.B = B self.SE = A self.SPB = [p*b*b for p,b in zip(P,B)] self.SB = B self.IP = [1/(p+0.000000000000001) for p in P] def merge(self, a, b): assert 0 <= a < self._n assert 0 <= b < self._n x, y = self.leader(a), self.leader(b) if x == y: return x if -self.parent_or_size[x] < -self.parent_or_size[y]: x, y = y, x self.parent_or_size[x] += self.parent_or_size[y] self.SB[x] += self.SB[y] self.SPB[x] += self.SPB[y] self.SE[x] += self.SE[y] self.IP[x] += self.IP[y] self.parent_or_size[y] = x return x def same(self, a, b): assert 0 <= a < self._n assert 0 <= b < self._n return self.leader(a) == self.leader(b) def leader(self, a): assert 0 <= a < self._n if self.parent_or_size[a] < 0: return a self.parent_or_size[a] = self.leader(self.parent_or_size[a]) return self.parent_or_size[a] def size(self, a): assert 0 <= a < self._n return -self.parent_or_size[self.leader(a)] def groups(self): leader_buf = [self.leader(i) for i in range(self._n)] result = [[] for _ in range(self._n)] for i in range(self._n): result[leader_buf[i]].append(i) return [r for r in result if r != []] N = int(input()) A = list(map(int,input().split())) B = list(map(int,input().split())) P = list(map(int,input().split())) D = DSU(N,B,P,A) Q = int(input()) ans = sum(p*(e-b)**2 for p,e,b in zip(P,A,B)) for _ in range(Q): x,y = map(int,input().split()) x -= 1 y -= 1 lx = D.leader(x) ly = D.leader(y) if D.same(x,y): print(ans) continue else: bef = (-D.SPB[lx] + (D.SE[lx] - D.SB[lx])**2/D.IP[lx] -D.SPB[ly] + (D.SE[ly] - D.SB[ly])**2/D.IP[ly] ) D.merge(x,y) lx = D.leader(x) aft = -D.SPB[lx] + (D.SE[lx] - D.SB[lx])**2/D.IP[lx] ans += aft-bef print(ans) # print(D.SB)