結果
問題 | No.2873 Kendall's Tau |
ユーザー | miya145592 |
提出日時 | 2024-09-06 22:39:41 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,425 ms / 4,500 ms |
コード長 | 2,298 bytes |
コンパイル時間 | 375 ms |
コンパイル使用メモリ | 82,428 KB |
実行使用メモリ | 217,736 KB |
最終ジャッジ日時 | 2024-09-06 22:40:05 |
合計ジャッジ時間 | 24,187 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
53,204 KB |
testcase_01 | AC | 38 ms
54,872 KB |
testcase_02 | AC | 38 ms
53,744 KB |
testcase_03 | AC | 39 ms
54,240 KB |
testcase_04 | AC | 38 ms
53,896 KB |
testcase_05 | AC | 39 ms
53,484 KB |
testcase_06 | AC | 39 ms
54,368 KB |
testcase_07 | AC | 1,333 ms
162,984 KB |
testcase_08 | AC | 1,405 ms
189,864 KB |
testcase_09 | AC | 1,361 ms
163,176 KB |
testcase_10 | AC | 1,425 ms
197,792 KB |
testcase_11 | AC | 1,341 ms
163,576 KB |
testcase_12 | AC | 1,364 ms
217,736 KB |
testcase_13 | AC | 496 ms
114,364 KB |
testcase_14 | AC | 1,108 ms
176,204 KB |
testcase_15 | AC | 325 ms
102,400 KB |
testcase_16 | AC | 307 ms
98,768 KB |
testcase_17 | AC | 1,006 ms
164,904 KB |
testcase_18 | AC | 776 ms
153,344 KB |
testcase_19 | AC | 978 ms
166,924 KB |
testcase_20 | AC | 317 ms
102,976 KB |
testcase_21 | AC | 834 ms
152,544 KB |
testcase_22 | AC | 410 ms
105,168 KB |
testcase_23 | AC | 837 ms
152,384 KB |
testcase_24 | AC | 207 ms
84,160 KB |
testcase_25 | AC | 334 ms
100,128 KB |
testcase_26 | AC | 985 ms
158,720 KB |
testcase_27 | AC | 690 ms
132,164 KB |
testcase_28 | AC | 1,194 ms
196,668 KB |
testcase_29 | AC | 1,263 ms
192,940 KB |
testcase_30 | AC | 270 ms
91,528 KB |
testcase_31 | AC | 405 ms
99,260 KB |
testcase_32 | AC | 844 ms
151,940 KB |
ソースコード
class SegTree: def __init__(self, op, e, n, v=None): self._n = n self._op = op self._e = e self._log = (n - 1).bit_length() self._size = 1 << self._log self._d = [self._e()] * (self._size << 1) if v is not None: for i in range(self._n): self._d[self._size + i] = v[i] for i in range(self._size - 1, 0, -1): self._d[i] = self._op(self._d[i << 1], self._d[i << 1 | 1]) def set(self, p, x): p += self._size self._d[p] = x while p: l, r = p, p^1 if l > r: l, r = r, l self._d[p >> 1] = self._op(self._d[l], self._d[r]) p >>= 1 def get(self, p): return self._d[p + self._size] #[l, r)の区間で求める def prod(self, l, r): sml, smr = self._e(), self._e() l += self._size r += self._size while l < r: if l & 1: sml = self._op(sml, self._d[l]) l += 1 if r & 1: r -= 1 smr = self._op(self._d[r], smr) l >>= 1 r >>= 1 return self._op(sml, smr) def all_prod(self): return self._d[1] def op(x, y): return x+y def e(): return 0 import math import sys input = sys.stdin.readline N = int(input()) XY = [list(map(int, input().split())) for _ in range(N)] s = set() for x, y in XY: s.add(x) s.add(y) s = list(s) s.sort() Z = dict() for i, ss in enumerate(s): Z[ss] = i xy = [] for x, y in XY: xx, yy = Z[x], Z[y] xy.append((xx, yy)) xy.sort() L = len(Z) ST = SegTree(op, e, L) tmp = [] bk_x = -1 P = 0 Q = 0 for x, y in xy: if x>bk_x: for t in tmp: ST.set(t, ST.get(t)+1) tmp = [] yminus = ST.prod(0, y) P += yminus yplus = ST.prod(y+1, L) Q += yplus tmp.append(y) bk_x = x X = dict() Y = dict() for x, y in XY: if x not in X: X[x] = 1 else: X[x] += 1 if y not in Y: Y[y] = 1 else: Y[y] += 1 R = 0 S = 0 cnt = 0 for key in X: cnt += X[key]*(X[key]-1)//2 R = N*(N-1)//2 - cnt cnt = 0 for key in Y: cnt += Y[key]*(Y[key]-1)//2 S = N*(N-1)//2 - cnt ans = (P-Q) / math.sqrt(R*S) print(ans)