結果
問題 | No.2873 Kendall's Tau |
ユーザー |
👑 |
提出日時 | 2024-09-06 21:46:33 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,758 bytes |
コンパイル時間 | 4,802 ms |
コンパイル使用メモリ | 266,628 KB |
最終ジャッジ日時 | 2025-02-24 04:12:17 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 13 WA * 17 |
ソースコード
#include<bits/stdc++.h>#include<atcoder/all>#define rep(i,n) for(int i=0;i<n;i++)using namespace std;using namespace atcoder;typedef long long ll;typedef vector<int> vi;typedef vector<long long> vl;typedef vector<vector<int>> vvi;typedef vector<vector<long long>> vvl;typedef long double ld;typedef pair<int, int> P;ostream& operator<<(ostream& os, const modint& a) {os << a.val(); return os;}template <int m> ostream& operator<<(ostream& os, const static_modint<m>& a) {os << a.val(); return os;}template <int m> ostream& operator<<(ostream& os, const dynamic_modint<m>& a) {os << a.val(); return os;}template<typename T> istream& operator>>(istream& is, vector<T>& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;}template<typename U, typename T> ostream& operator<<(ostream& os, const pair<U, T>& p){os << p.first << ' ' << p.second; return os;}template<typename T> ostream& operator<<(ostream& os, const vector<T>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); returnos;}template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : "");return os;}template<typename T> ostream& operator<<(ostream& os, const set<T>& se){for(T x : se) os << x << " "; os << "\n"; return os;}template<typename T> ostream& operator<<(ostream& os, const unordered_set<T>& se){for(T x : se) os << x << " "; os << "\n"; return os;}template<typename S, auto op, auto e> ostream& operator<<(ostream& os, const atcoder::segtree<S, op, e>& seg){int n = seg.max_right(0, [](S){returntrue;}); rep(i, n) os << seg.get(i) << (i == n - 1 ? "\n" : " "); return os;}template<typename S, auto op, auto e, typename F, auto mapping, auto composition, auto id> ostream& operator<<(ostream& os, const atcoder::lazy_segtree<S, op, e, F, mapping, composition, id>& seg){int n = seg.max_right(0, [](S){return true;}); rep(i, n) os << seg.get(i) << (i == n- 1 ? "\n" : " "); return os;}template<typename T> void chmin(T& a, T b){a = min(a, b);}template<typename T> void chmax(T& a, T b){a = max(a, b);}// Coodinate Compression// https://youtu.be/fR3W5IcBGLQ?t=8550template<typename T=int>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();}};using S = int;S op(S a, S b){return a + b;}S e(){return 0;}int main(){int n;cin >> n;CC<int> cc_x;CC<int> cc_y;vector<int> x(n), y(n);rep(i, n){cin >> x[i] >> y[i];cc_x.add(x[i]);cc_y.add(y[i]);}long long p = 0, q = 0, r = 0,s = 0;map<int, int> ma_x, ma_y;rep(i, n) ma_x[x[i]]++;rep(i, n) ma_y[y[i]]++;for(auto [key, val] : ma_x) r += (long long)(n - val) * val;for(auto [key, val] : ma_y) s += (long long)(n - val) * val;r /= 2;s /= 2;int ny = cc_y.size();segtree<S, op, e> seg(ny);map<int, vector<int>> event;rep(i, n) event[x[i]].push_back(i);for(auto& [x_val, vec] : event){for(auto idx : vec){p += seg.prod(0, cc_y(y[idx]));q += seg.prod(cc_y(y[idx]) + 1, cc_y.size());}for(auto idx : vec){auto val = seg.get(cc_y(y[idx]));seg.set(cc_y(y[idx]), val + 1);}}// cout << p << ' ' << q << ' ' << r << ' ' << s << "\n";long double ans = (p - q);ans /= sqrtl(r * s);cout << setprecision(15);cout << ans << "\n";return 0;}