結果

問題 No.2873 Kendall's Tau
ユーザー Kude
提出日時 2024-09-07 09:40:52
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 191 ms / 4,500 ms
コード長 2,230 bytes
コンパイル時間 3,814 ms
コンパイル使用メモリ 295,180 KB
実行使用メモリ 9,100 KB
最終ジャッジ日時 2024-09-07 09:41:01
合計ジャッジ時間 8,478 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
template <class S>
struct value_compression : vector<S> {
bool built = false;
using VS = vector<S>;
using VS::VS;
value_compression(vector<S> v) : vector<S>(move(v)) {}
void build() {
sort(this->begin(), this->end());
this->erase(unique(this->begin(), this->end()), this->end());
built = true;
}
template <class T>
void convert(T first, T last) {
assert(built);
for (; first != last; ++first) *first = (*this)(*first);
}
int operator()(S x) {
assert(built);
return lower_bound(this->begin(), this->end(), x) - this->begin();
}
void clear() {
this->clear();
built = false;
}
};
} int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<P> xy(n);
value_compression<int> vc_x, vc_y;
for (auto& [x, y] : xy) cin >> x >> y, vc_x.emplace_back(x), vc_y.emplace_back(y);
vc_x.build();
vc_y.build();
for (auto& [x, y] : xy) x = vc_x(x), y = vc_y(y);
ll p = 0, q = 0, r = n * ll(n - 1) / 2, s = r;
ranges::sort(xy, {}, [](const P& p) { return P(p.first, -p.second); });
fenwick_tree<int> ft(n);
for (auto [x, y] : xy) p += ft.sum(0, y), ft.add(y, 1);
ranges::sort(xy, {}, [](const P& p) { return P(-p.first, -p.second); });
ft = fenwick_tree<int>(n);
for (auto [x, y] : xy) q += ft.sum(0, y), ft.add(y, 1);
VI cntx(n), cnty(n);
for (auto [x, y] : xy) r -= cntx[x]++, s -= cnty[y]++;
auto res = (p - q) / sqrtl(__int128(r) * s);
cout << fixed << setprecision(16) << res << '\n';
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0