結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 651 ms
31,012 KB
testcase_08 AC 755 ms
41,660 KB
testcase_09 AC 659 ms
30,708 KB
testcase_10 AC 800 ms
45,480 KB
testcase_11 AC 660 ms
29,684 KB
testcase_12 AC 707 ms
39,368 KB
testcase_13 AC 180 ms
12,800 KB
testcase_14 AC 600 ms
36,348 KB
testcase_15 AC 103 ms
10,624 KB
testcase_16 AC 98 ms
9,600 KB
testcase_17 AC 471 ms
25,576 KB
testcase_18 AC 376 ms
24,152 KB
testcase_19 AC 481 ms
27,060 KB
testcase_20 AC 103 ms
9,984 KB
testcase_21 AC 373 ms
20,760 KB
testcase_22 AC 147 ms
11,596 KB
testcase_23 AC 392 ms
21,600 KB
testcase_24 AC 44 ms
6,940 KB
testcase_25 AC 93 ms
10,112 KB
testcase_26 AC 462 ms
23,144 KB
testcase_27 AC 297 ms
20,264 KB
testcase_28 AC 594 ms
34,548 KB
testcase_29 AC 605 ms
32,396 KB
testcase_30 AC 71 ms
7,824 KB
testcase_31 AC 140 ms
11,136 KB
testcase_32 AC 386 ms
23,364 KB
権限があれば一括ダウンロードができます

ソースコード

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) / sqrtl(r) / sqrtl(s);
	cout << setprecision(15);
	cout << ans << "\n";
	return 0;
}
0