結果

問題 No.2873 Kendall's Tau
ユーザー 👑 binapbinap
提出日時 2024-09-06 21:46:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,758 bytes
コンパイル時間 4,988 ms
コンパイル使用メモリ 279,276 KB
実行使用メモリ 45,472 KB
最終ジャッジ日時 2024-09-06 21:47:02
合計ジャッジ時間 16,877 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 174 ms
12,800 KB
testcase_14 WA -
testcase_15 AC 100 ms
10,624 KB
testcase_16 AC 98 ms
9,472 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 103 ms
9,856 KB
testcase_21 WA -
testcase_22 AC 144 ms
11,464 KB
testcase_23 WA -
testcase_24 AC 43 ms
6,940 KB
testcase_25 AC 94 ms
10,240 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 70 ms
7,572 KB
testcase_31 AC 143 ms
11,008 KB
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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" : " "); return os;}
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){return true;}); 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=8550
template<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;
}
0