結果
| 問題 |
No.2873 Kendall's Tau
|
| コンテスト | |
| ユーザー |
Today03
|
| 提出日時 | 2024-09-06 22:38:27 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,237 bytes |
| コンパイル時間 | 3,324 ms |
| コンパイル使用メモリ | 269,396 KB |
| 実行使用メモリ | 28,172 KB |
| 最終ジャッジ日時 | 2024-09-06 22:38:38 |
| 合計ジャッジ時間 | 11,184 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 WA * 17 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9 + 10;
const ll INFL = 4e18;
/*
考察
P:=(i,j)(i<j)であって、二次元平面でjがiの右上にあるような組の個数
Q:=(i,j)(i<j)であって、二次元平面でjがiの右下にあるような組の個数
->座標圧縮して平面走査かな
*/
template <typename T>
struct FenwickTree {
FenwickTree() = default;
FenwickTree(int n) {
this->n = n;
dat = vector<T>(n);
}
void add(int i, T x) {
i++;
while (i <= n) {
dat[i - 1] += x;
i += i & -i;
}
}
T sum(int l, int r) {
return sum(r) - sum(l);
}
T operator[](int i) {
return sum(i, i + 1);
}
int size() {
return n;
}
private:
int n;
vector<T> dat;
T sum(int r) {
T ret = 0;
while (r > 0) {
ret += dat[r - 1];
r -= r & -r;
}
return ret;
}
};
int main() {
int N;
cin >> N;
vector<int> val;
vector<pair<int, int>> P(N);
for (int i = 0; i < N; i++) {
cin >> P[i].first >> P[i].second;
val.push_back(P[i].first);
val.push_back(P[i].second);
}
ranges::sort(val);
val.erase(unique(val.begin(), val.end()), val.end());
auto get = [&](ll x) {
return ranges::lower_bound(val, x) - val.begin();
};
vector<vector<int>> YS(N * 2);
for (int i = 0; i < N; i++) YS[get(P[i].first)].push_back(get(P[i].second));
FenwickTree<ll> ft(N * 2);
ll cup = 0, cdw = 0;
for (int i = N * 2 - 1; i >= 0; i--) {
for (int y : YS[i]) {
cup += ft.sum(y + 1, 2 * N);
cdw += ft.sum(0, y);
}
for (int y : YS[i]) ft.add(y, 1);
}
vector<int> cntx(N * 2), cnty(N * 2);
for (int i = 0; i < N; i++) {
cntx[get(P[i].first)]++;
cnty[get(P[i].second)]++;
}
ll cx = 0, cy = 0;
for (int i = 0; i < N * 2; i++) {
cx += 1ll * (N - cntx[i]) * cntx[i];
cy += 1ll * (N - cnty[i]) * cnty[i];
}
cx /= 2;
cy /= 2;
double ans = 1.0 * (cup - cdw) / sqrt(cx * cy);
printf("%.10lf\n", ans);
}
Today03