結果
問題 | No.2873 Kendall's Tau |
ユーザー |
![]() |
提出日時 | 2024-09-07 01:33:30 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 206 ms / 4,500 ms |
コード長 | 1,557 bytes |
コンパイル時間 | 2,664 ms |
コンパイル使用メモリ | 213,852 KB |
最終ジャッジ日時 | 2025-02-24 05:05:39 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include <bits/stdc++.h>using namespace std;void fast_io() {ios_base::sync_with_stdio(false);cin.tie(nullptr);}#include <atcoder/fenwicktree>using namespace atcoder;int main() {fast_io();int n;cin >> n;vector<pair<int, int>> xy(n);vector<int> vals;for (int i = 0; i < n; i++) {cin >> xy[i].first >> xy[i].second;vals.push_back(xy[i].first);vals.push_back(xy[i].second);}sort(vals.begin(), vals.end());vals.erase(unique(vals.begin(), vals.end()), vals.end());int m = vals.size();for (int i = 0; i < n; i++) {xy[i].first =lower_bound(vals.begin(), vals.end(), xy[i].first) - vals.begin();xy[i].second =lower_bound(vals.begin(), vals.end(), xy[i].second) - vals.begin();}long long r = (long long)n * (n - 1) / 2, s = r;{vector<int> cnt_x(m), cnt_y(m);for (auto [x, y] : xy) {r -= cnt_x[x];cnt_x[x]++;s -= cnt_y[y];cnt_y[y]++;}}long long p = 0;{sort(xy.begin(), xy.end(), [&](auto a, auto b) {if (a.first == b.first) return a.second > b.second;return a.first < b.first;});fenwick_tree<long long> fw(m);for (auto [_, y] : xy) {p += fw.sum(0, y);fw.add(y, 1);}}long long q = 0;{sort(xy.begin(), xy.end(), [&](auto a, auto b) {if (a.first == b.first) return a.second < b.second;return a.first < b.first;});fenwick_tree<long long> fw(m);for (auto [_, y] : xy) {q += fw.sum(y + 1, m);fw.add(y, 1);}}long double ans = (p - q) / sqrtl(r) / sqrtl(s);cout << fixed << setprecision(16) << ans << endl;}