問題一覧 > 通常問題

No.2873 Kendall's Tau

レベル : / AI推定難易度 : 1500 / 実行時間制限 : 1ケース 4.500秒 / メモリ制限 : 512 MB / 小数誤差許容問題 絶対誤差または相対誤差が $10^{-6}$ 以下。ただし、ジャッジ側の都合で500桁未満にしてください
タグ : (AC するまで非表示) / 解いたユーザー数 79
作問者 : 寝癖 / テスター : yuusaan 👑 seekworser
お気に入りにしたユーザー ProblemId : 11163 / 自分の提出
問題文最終更新日: 2024-07-17 23:44:48
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 444 (順位表) の他の問題:

Problem Statement

Given $N$ data points $(x_1,y_1),\cdots,(x_N,y_N)$, find Kendall's rank correlation coefficient.

Here, Kendall's rank correlation coefficient $\tau$ is defined as follows. \[\tau=\frac{P-Q}{\sqrt{R\times S}}\]

  • $P$: the number of pairs of distinct indices $(i, j)\ (1\le i < j\le N)$ such that $(x_i-x_j)(y_i-y_j)> 0$
  • $Q$: the number of pairs of distinct indices $(i, j)\ (1\le i < j\le N)$ such that $(x_i-x_j)(y_i-y_j)< 0$
  • $R$: the number of pairs of distinct indices $(i, j)\ (1\le i < j\le N)$ such that $x_i\neq x_j$
  • $S$: the number of pairs of distinct indices $(i, j)\ (1\le i < j\le N)$ such that $y_i\neq y_j$

Under the constraints of this problem, it is guaranteed that $R\times S\neq0$.

Input

$N$
$x_1\ y_1$
$\vdots$
$x_N\ y_N$
  • $2\le N\le 2\times10^5$
  • $|x_i|,|y_i|\le10^9$ for all $i$
  • There exists a pair of distinct indices $(i,j)$ such that $x_i\neq x_j$
  • There exists a pair of distinct indices $(i,j)$ such that $y_i\neq y_j$
  • All input values are integers

Output

Print Kendall's rank correlation coefficient on a single line.

Your answer is judged as correct if its absolute or relative error from the expected answer is at most $10^{-6}$.

Sample

Sample 1
Input
3
1 4
1 5
9 2
Output
-0.8164965809277260

The values of $P,Q,R,S$ in the definition of Kendall's rank correlation coefficient are as follows.

  • $P=0$, since no pair satisfies the condition
  • $Q=2$, since the pairs $(1,3),(2,3)$ satisfy the condition
  • $R=2$, since the pairs $(1,3),(2,3)$ satisfy the condition
  • $S=3$, since the pairs $(1,2),(1,3),(2,3)$ satisfy the condition

Therefore, the required value is $\frac{0-2}{\sqrt{2\times3}}=-\frac{2}{\sqrt{6}}=0.816496...$.

Sample 2
Input
2
1 1
2 2
Output
1.0000000000000000

Sample 3
Input
5
4 4
5 7
0 4
2 10
-6 4
Output
0.3585685828003181

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。