結果

問題 No.2873 Kendall's Tau
ユーザー t98slidert98slider
提出日時 2024-09-07 17:48:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 128 ms / 4,500 ms
コード長 1,210 bytes
コンパイル時間 4,641 ms
コンパイル使用メモリ 271,832 KB
実行使用メモリ 7,168 KB
最終ジャッジ日時 2024-09-07 17:48:20
合計ジャッジ時間 8,402 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 128 ms
6,940 KB
testcase_08 AC 124 ms
7,040 KB
testcase_09 AC 123 ms
6,944 KB
testcase_10 AC 124 ms
7,168 KB
testcase_11 AC 123 ms
6,940 KB
testcase_12 AC 118 ms
7,040 KB
testcase_13 AC 39 ms
6,944 KB
testcase_14 AC 101 ms
6,940 KB
testcase_15 AC 22 ms
6,940 KB
testcase_16 AC 23 ms
6,944 KB
testcase_17 AC 94 ms
6,940 KB
testcase_18 AC 67 ms
6,940 KB
testcase_19 AC 88 ms
6,940 KB
testcase_20 AC 23 ms
6,944 KB
testcase_21 AC 75 ms
6,944 KB
testcase_22 AC 33 ms
6,940 KB
testcase_23 AC 76 ms
6,940 KB
testcase_24 AC 11 ms
6,940 KB
testcase_25 AC 20 ms
6,940 KB
testcase_26 AC 94 ms
6,940 KB
testcase_27 AC 57 ms
6,944 KB
testcase_28 AC 104 ms
6,940 KB
testcase_29 AC 114 ms
6,944 KB
testcase_30 AC 17 ms
6,944 KB
testcase_31 AC 32 ms
6,940 KB
testcase_32 AC 76 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    ll P = 0, R = 0, S = 0, cn = 0;
    vector<pair<int,int>> a(n);
    vector<int> cy(n);
    for(int i = 0; i < n; i++){
        auto &&[x, y] = a[i];
        cin >> x >> y;
        cy[i] = y;
    }
    sort(a.begin(), a.end());
    sort(cy.begin(), cy.end());
    cy.erase(unique(cy.begin(), cy.end()), cy.end());
    const int m = cy.size();
    atcoder::fenwick_tree<int> fw(m);
    vector<int> cnty(m);
    for(int l = 0, r = 0; l < n; l = r){
        while(r < n && a[r].first == a[l].first) r++;
        R += cn * (r - l);
        for(int i = l; i < r; i++){
            a[i].second = lower_bound(cy.begin(), cy.end(), a[i].second) - cy.begin();
            int low = fw.sum(0, a[i].second);
            int up = cn - cnty[a[i].second] - low;
            P += low - up;
        }
        for(int i = l; i < r; i++){
            cn++, cnty[a[i].second]++;
            S += cn - cnty[a[i].second];
            fw.add(a[i].second, 1);
        }
    }
    cout << fixed << setprecision(15) << P / sqrtl((double)R * S) << '\n';
}
0