結果
| 問題 |
No.2873 Kendall's Tau
|
| コンテスト | |
| ユーザー |
maeshun
|
| 提出日時 | 2024-09-08 13:35:35 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,161 bytes |
| コンパイル時間 | 4,430 ms |
| コンパイル使用メモリ | 267,004 KB |
| 最終ジャッジ日時 | 2025-02-24 05:33:47 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 WA * 20 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for(int i=0;i<(n);++i)
#define rep1(i, n) for(int i=1;i<=(n);i++)
#define ll long long
using 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=8550
template<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()
{
int n;
cin >> n;
vector<pair<int, int>> 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);
int sy = cy.size();
fenwick_tree<int> bit(sy);
int p = 0;
int q = 0;
for(int i=0;i<n;) {
int j = i;
vector<int> y;
while(j<n && vs[j].first==vs[i].first) {
y.push_back(cy(vs[j].second));
j++;
}
for(int Y : y) {
dbg(Y);
p += bit.sum(0, Y);
q += bit.sum(Y+1, sy);
}
for(int Y : y) {
bit.add(Y,1);
}
i = j;
}
map<int,int> x, y;
ll r = n * (n-1)/2;
ll 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;
}
maeshun