結果

問題 No.2873 Kendall's Tau
ユーザー 👑 kmjpkmjp
提出日時 2024-09-06 23:27:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 464 ms / 4,500 ms
コード長 2,189 bytes
コンパイル時間 2,880 ms
コンパイル使用メモリ 224,284 KB
実行使用メモリ 34,336 KB
最終ジャッジ日時 2024-09-06 23:27:43
合計ジャッジ時間 10,711 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
10,036 KB
testcase_01 AC 3 ms
11,948 KB
testcase_02 AC 3 ms
10,032 KB
testcase_03 AC 3 ms
10,032 KB
testcase_04 AC 4 ms
11,944 KB
testcase_05 AC 3 ms
9,908 KB
testcase_06 AC 3 ms
11,816 KB
testcase_07 AC 405 ms
25,504 KB
testcase_08 AC 454 ms
31,268 KB
testcase_09 AC 392 ms
26,180 KB
testcase_10 AC 464 ms
34,336 KB
testcase_11 AC 367 ms
28,784 KB
testcase_12 AC 454 ms
30,908 KB
testcase_13 AC 96 ms
16,020 KB
testcase_14 AC 358 ms
31,028 KB
testcase_15 AC 56 ms
16,260 KB
testcase_16 AC 55 ms
15,552 KB
testcase_17 AC 266 ms
25,280 KB
testcase_18 AC 200 ms
21,684 KB
testcase_19 AC 272 ms
25,344 KB
testcase_20 AC 59 ms
16,092 KB
testcase_21 AC 226 ms
21,272 KB
testcase_22 AC 85 ms
13,472 KB
testcase_23 AC 215 ms
19,052 KB
testcase_24 AC 25 ms
11,284 KB
testcase_25 AC 51 ms
13,696 KB
testcase_26 AC 251 ms
24,452 KB
testcase_27 AC 155 ms
16,972 KB
testcase_28 AC 340 ms
26,072 KB
testcase_29 AC 358 ms
28,328 KB
testcase_30 AC 39 ms
14,468 KB
testcase_31 AC 75 ms
16,320 KB
testcase_32 AC 227 ms
18,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N;
ll P,Q,R,S;
ll X[202020],Y[202020];
map<int,int> Xs,Ys;


template<class V, int ME> class BIT {
public:
	V bit[1<<ME];
	V operator()(int e) {if(e<0) return 0;V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;}
	void add(int e,V v) { e++; while(e<=1<<ME) bit[e-1]+=v,e+=e&-e;}
};
BIT<int,20> bt1,bt2;

bool cmp(vector<ll>& L,vector<ll>& R) {
	ll a=L[1]*R[0]-L[0]*R[1];
	if(a<0) return 1;
	if(a>0) return 0;
	return L[2]<R[2];
}
bool cmp2(vector<ll>& L,vector<ll>& R) {
	ll a=L[1]*R[0]-L[0]*R[1];
	if(a>0) return 1;
	if(a<0) return 0;
	return L[2]<R[2];
}
bool cmp3(vector<ll>& L,vector<ll>& R) {
	ll a=L[1]*R[0]-L[0]*R[1];
	if(a>=0) return 1;
	return 0;
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	vector<ll> YY={-1<<30};
	FOR(i,N) {
		cin>>X[i]>>Y[i];
		YY.push_back(Y[i]);
		Xs[X[i]]++;
		Ys[Y[i]]++;
	}
	FORR2(a,b,Xs) R+=b*(N-b);
	FORR2(a,b,Ys) S+=b*(N-b);
	sort(ALL(YY));
	YY.erase(unique(ALL(YY)),YY.end());
	
	vector<pair<int,int>> Ps[2];
	
	FOR(i,N) {
		Y[i]=lower_bound(ALL(YY),Y[i])-YY.begin();
		Ps[0].push_back({-X[i],Y[i]});
		Ps[1].push_back({X[i],Y[i]});
	}
	
	sort(ALL(Ps[0]));
	sort(ALL(Ps[1]));
	FORR2(x,y,Ps[0]) {
		P+=bt1(N)-bt1(y);
		bt1.add(y,1);
	}
	FORR2(x,y,Ps[1]) {
		Q+=bt2(N)-bt2(y);
		bt2.add(y,1);
	}
	
	
	
	R/=2;
	S/=2;
	double a=R;
	a*=S;
	a=sqrt(a);
	double b=P-Q;
	//cout<<P<<" "<<Q<<" "<<R<<" "<<S<<endl;
	_P("%.12lf\n",b/a);
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0