結果
問題 |
No.2873 Kendall's Tau
|
ユーザー |
![]() |
提出日時 | 2024-09-07 01:40:15 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 302 ms / 4,500 ms |
コード長 | 2,153 bytes |
コンパイル時間 | 2,258 ms |
コンパイル使用メモリ | 208,512 KB |
最終ジャッジ日時 | 2025-02-24 05:05:54 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #define ALL(v) v.begin(),v.end() #define dbg(x) cerr << #x << ": " << (x) << endl; template<class F, class S> ostream& operator<<(ostream& os, pair<F,S>& p) { os << '(' << p.first << ',' << p.second << ')'; return os; } template<class Iter> void print(Iter beg, Iter end) { for (Iter itr = beg; itr != end; ++itr) { cerr << *itr << ' '; } cerr << '\n'; } struct BIT { int n; vector<ll> d; BIT (int n) : n(n), d(n+1) {} void add(int idx, ll val) { ++idx; for (int x = idx; x <= n; x += x&-x) { d[x] += val; } } ll sum(int idx) { ll res = 0; for (int x = idx; x > 0; x -= x&-x) { res += d[x]; } return res; } ll sum(int l, int r) { return sum(r) - sum(l); } }; int n; vector<int> x,y; int main() { cin >> n; x.resize(n); y.resize(n); for (int i = 0; i < n; ++i) cin >> x[i] >> y[i]; auto tmp = x; sort(ALL(tmp)); tmp.erase(unique(ALL(tmp)), tmp.end()); for (int i = 0; i < n; ++i) x[i] = lower_bound(ALL(tmp), x[i]) - tmp.begin(); int xmax = tmp.size(); tmp = y; sort(ALL(tmp)); tmp.erase(unique(ALL(tmp)), tmp.end()); for (int i = 0; i < n; ++i) y[i] = lower_bound(ALL(tmp), y[i]) - tmp.begin(); int ymax = tmp.size(); ll p=0, q=0, r=0, s=0; BIT bit(ymax); vector<vector<int>> ys(xmax); for (int i = 0; i < n; ++i) ys[x[i]].push_back(y[i]); for (int i = 0; i < xmax; ++i) { for (int j : ys[i]) { p += bit.sum(j); q += bit.sum(j+1, ymax); } for (int j : ys[i]) { bit.add(j, 1); } } vector<int> mx(xmax),my(ymax); for (int i = 0; i < n; ++i) { mx[x[i]]++; my[y[i]]++; } for (int i = 0; i < xmax; ++i) { r += (ll)mx[i] * (n - mx[i]); } for (int i = 0; i < ymax; ++i) { s += (ll)my[i] * (n - my[i]); } r >>= 1; s >>= 1; double ans = (p - q) / (sqrt(r) * sqrt(s)); cout << fixed << setprecision(20) << ans << '\n'; }