結果
| 問題 |
No.2873 Kendall's Tau
|
| コンテスト | |
| ユーザー |
SnowBeenDiding
|
| 提出日時 | 2024-09-06 22:08:35 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 756 ms / 4,500 ms |
| コード長 | 1,964 bytes |
| コンパイル時間 | 5,672 ms |
| コンパイル使用メモリ | 325,840 KB |
| 実行使用メモリ | 16,268 KB |
| 最終ジャッジ日時 | 2024-09-06 22:09:16 |
| 合計ジャッジ時間 | 16,954 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
#include <atcoder/all>
#include <bits/stdc++.h>
#define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
using namespace atcoder;
using namespace std;
typedef long long ll;
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();
}
};
ll f(int n, vector<int> x, vector<int> y) {
ll ret = 0;
CC<int> cc;
rep(i, 0, n) { cc.add(y[i]); }
rep(i, 0, n) { y[i] = cc(y[i]); }
vector<pair<int, int>> p(n);
rep(i, 0, n) p[i] = {x[i], -y[i]};
sort(p.begin(), p.end());
fenwick_tree<int> fw(n);
for (auto [x, y] : p) {
y *= -1;
ret += fw.sum(0, y);
fw.add(y, 1);
}
return ret;
}
ll g(int n, vector<int> x) {
ll ret = 0;
map<int, int> ma;
rep(i, 0, n) { ma[x[i]]++; }
rep(i, 0, n) { ret += n - ma[x[i]]; }
ret /= 2;
return ret;
}
int main() {
int n;
cin >> n;
vector<int> x(n), y(n);
rep(i, 0, n) cin >> x[i] >> y[i];
vector<int> xm(n), ym(n);
rep(i, 0, n) {
xm[i] = -x[i];
ym[i] = -y[i];
}
double P = f(n, x, y) + f(n, xm, ym);
rep(i, 0, n) { x[i] *= -1; }
double Q = f(n, x, y) + f(n, xm, ym);
rep(i, 0, n) { x[i] *= -1; }
double R = g(n, x);
double S = g(n, y);
cerr << P << " " << Q << " " << R << " " << S << endl;
double ans = (P - Q) / sqrt(R * S);
cout << fixed << setprecision(15) << ans << endl;
}
SnowBeenDiding