結果
| 問題 |
No.2873 Kendall's Tau
|
| コンテスト | |
| ユーザー |
hongrock
|
| 提出日時 | 2024-09-06 22:15:11 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 599 ms / 4,500 ms |
| コード長 | 1,276 bytes |
| コンパイル時間 | 2,377 ms |
| コンパイル使用メモリ | 209,220 KB |
| 最終ジャッジ日時 | 2025-02-24 04:28:04 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define pb emplace_back
#define mp make_pair
using ll = long long;
using pii = pair<int,int>;
constexpr int mod = 998244353;
constexpr int inf = 0x3f3f3f3f;
constexpr int N = 2e5 + 10;
int n, m, b[N];
int s[N];
int lowbit(int x){
return x & (-x);
}
void add(int x, int v){
for(; x<=m; x+=lowbit(x)) s[x] += v;
}
int sum(int x){
int ret = 0;
for(; x>0; x-=lowbit(x)) ret += s[x];
return ret;
}
int query(int L, int R){
if(L > R) return 0;
return sum(R) - sum(L - 1);
}
void _main(){
unordered_map<int, int> cntx, cnty;
map<int, vector<int>> g;
cin >> n;
ll P = 0, Q = 0, R = 0, S = 0;
int x, y;
m = 0;
for(int i=1; i<=n; ++i){
cin >> x >> y;
R += (i - ++cntx[x]);
S += (i - ++cnty[y]);
g[x].pb(y);
b[m++] = y;
}
sort(b, b+m);
m = unique(b, b+m) - b;
for(auto &[x, vec] : g){
for(int y : vec){
int j = lower_bound(b, b+m, y) - b + 1;
P += query(1, j - 1);
Q += query(j + 1, m);
}
for(int y : vec){
int j = lower_bound(b, b+m, y) - b + 1;
add(j, 1);
}
}
cout << setprecision(8) << (P - Q) * 1.0 / sqrt(1.0 * R * S) << '\n';
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
_main();
return 0;
}
hongrock