結果
問題 | No.2873 Kendall's Tau |
ユーザー |
![]() |
提出日時 | 2024-09-06 23:09:50 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 605 ms / 4,500 ms |
コード長 | 1,182 bytes |
コンパイル時間 | 2,453 ms |
コンパイル使用メモリ | 211,816 KB |
最終ジャッジ日時 | 2025-02-24 04:55:15 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include<bits/stdc++.h> #include<atcoder/fenwicktree> using namespace std; int N,X[2<<17],Y[2<<17]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin>>N; map<int,vector<int>>mpX,mpY; for(int i=0;i<N;i++) { cin>>X[i]>>Y[i]; mpX[X[i]].push_back(Y[i]); mpY[Y[i]].push_back(X[i]); } vector<int>ord(N); vector<int> B(Y,Y+N); sort(B.begin(),B.end()); B.erase(unique(B.begin(),B.end()),B.end()); atcoder::fenwick_tree<int>BIT(B.size()); long P=0,Q=0; for(auto[key,val]:mpX) { for(int y:val) { y=lower_bound(B.begin(),B.end(),y)-B.begin(); P+=BIT.sum(0,y); Q+=BIT.sum(y+1,B.size()); } for(int y:val) { y=lower_bound(B.begin(),B.end(),y)-B.begin(); BIT.add(y,1); } } long R=long(N)*(N-1)/2; long S=R; for(auto[key,val]:mpX) { long x=val.size(); R-=x*(x-1)/2; } for(auto[key,val]:mpY) { long x=val.size(); S-=x*(x-1)/2; } double ans=P-Q; ans/=sqrtl(double(R)*S); cout<<fixed<<setprecision(16)<<ans<<endl; }