結果
問題 | No.2873 Kendall's Tau |
ユーザー |
![]() |
提出日時 | 2024-09-08 13:46:55 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 497 ms / 4,500 ms |
コード長 | 2,126 bytes |
コンパイル時間 | 4,915 ms |
コンパイル使用メモリ | 269,220 KB |
最終ジャッジ日時 | 2025-02-24 05:36:34 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include <bits/stdc++.h>#include <atcoder/all>using namespace std;using namespace atcoder;#define rep(i, n) for(ll i=0;i<(n);++i)#define rep1(i, n) for(int i=1;i<=(n);i++)#define ll long longusing mint = modint998244353;using P = pair<ll,ll>;using lb = long double;using T = tuple<ll, ll, ll>;#ifdef LOCAL# include <debug_print.hpp># define dbg(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)#else# define dbg(...) (static_cast<void>(0))#endif// Coodinate Compression// https://youtu.be/fR3W5IcBGLQ?t=8550template<typename T=long long>struct CC {bool initialized;vector<T> xs;CC(): initialized(false) {}void add(T x) { xs.push_back(x);}void init() {sort(xs.begin(), xs.end());xs.erase(unique(xs.begin(),xs.end()),xs.end());initialized = true;}int operator()(T x) {if (!initialized) init();return upper_bound(xs.begin(), xs.end(), x) - xs.begin() - 1;}T operator[](int i) {if (!initialized) init();return xs[i];}int size() {if (!initialized) init();return xs.size();}};int main(){ll n;cin >> n;vector<pair<ll, ll>> vs(n);rep(i,n) cin >> vs[i].first >> vs[i].second;sort(vs.begin(),vs.end());CC cx, cy;rep(i,n) cy.add(vs[i].second);ll sy = cy.size();ll p = 0;ll q = 0;fenwick_tree<ll> bit(sy);for(ll i=0;i<n;) {ll j = i;vector<ll> y;while(j<n && vs[j].first==vs[i].first) {y.push_back(cy(vs[j].second));j++;}for(ll Y : y) {p += bit.sum(0, Y);q += bit.sum(Y+1, sy);}for(ll Y : y) {bit.add(Y,1);}i = j;}map<ll,ll> x, y;lb r = n * (n-1)/2;lb s = n * (n-1)/2;rep(i,n) x[vs[i].first]++;rep(i,n) y[vs[i].second]++;for(auto p : x) {r -= (ll)p.second*(p.second-1)/2;}for(auto p : y) {s -= (ll)p.second*(p.second-1)/2;}dbg(p,q,r,s);lb ans = (p-q) / sqrt(r*s);cout << fixed << setprecision(16) << ans << endl;return 0;}