結果

問題 No.1365 [Cherry 1st Tune] Whose Fault?
ユーザー vkgainzvkgainz
提出日時 2021-06-12 13:49:34
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 788 ms / 2,000 ms
コード長 1,652 bytes
コンパイル時間 3,959 ms
コンパイル使用メモリ 133,728 KB
実行使用メモリ 53,892 KB
最終ジャッジ日時 2023-08-22 11:26:52
合計ジャッジ時間 32,126 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,224 KB
testcase_01 AC 2 ms
6,124 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 3 ms
5,916 KB
testcase_04 AC 3 ms
6,064 KB
testcase_05 AC 3 ms
6,120 KB
testcase_06 AC 2 ms
6,076 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 3 ms
6,132 KB
testcase_10 AC 3 ms
7,636 KB
testcase_11 AC 2 ms
6,260 KB
testcase_12 AC 3 ms
6,168 KB
testcase_13 AC 69 ms
9,856 KB
testcase_14 AC 48 ms
10,656 KB
testcase_15 AC 13 ms
8,908 KB
testcase_16 AC 11 ms
10,872 KB
testcase_17 AC 41 ms
9,932 KB
testcase_18 AC 24 ms
8,364 KB
testcase_19 AC 69 ms
10,092 KB
testcase_20 AC 58 ms
6,840 KB
testcase_21 AC 63 ms
9,468 KB
testcase_22 AC 52 ms
8,076 KB
testcase_23 AC 155 ms
30,060 KB
testcase_24 AC 323 ms
36,076 KB
testcase_25 AC 631 ms
38,196 KB
testcase_26 AC 443 ms
34,136 KB
testcase_27 AC 532 ms
19,324 KB
testcase_28 AC 245 ms
10,624 KB
testcase_29 AC 183 ms
19,996 KB
testcase_30 AC 788 ms
42,892 KB
testcase_31 AC 705 ms
48,884 KB
testcase_32 AC 407 ms
44,508 KB
testcase_33 AC 644 ms
27,612 KB
testcase_34 AC 502 ms
25,324 KB
testcase_35 AC 294 ms
36,116 KB
testcase_36 AC 587 ms
49,512 KB
testcase_37 AC 126 ms
17,396 KB
testcase_38 AC 166 ms
38,712 KB
testcase_39 AC 743 ms
36,356 KB
testcase_40 AC 744 ms
36,480 KB
testcase_41 AC 563 ms
42,976 KB
testcase_42 AC 540 ms
20,020 KB
testcase_43 AC 3 ms
5,988 KB
testcase_44 AC 340 ms
53,892 KB
testcase_45 AC 437 ms
6,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int par[100001], sz[100001];
int freq[100001][11][11];
long long X[100001];
double val[100001];
double ans;

int find(int x) {
    if(x == par[x]) return x;
    return par[x] = find(par[x]);
}

void merge(int x, int y) {
    if(find(x) == find(y)) return;
    x = find(x), y = find(y);
    if(sz[x] < sz[y]) swap(x, y);
    X[x] += X[y];
    par[y] = x;
    sz[x] += sz[y];
    ans -= val[x];
    ans -= val[y];
    double num = X[x], den = 0.0;
    bool zer = false;
    for(int i = 0; i <= 10; i++) {
        for(int j = 0; j <= 10; j++) {
            freq[x][i][j] += freq[y][i][j];
            num -= freq[x][i][j] * j;
            if(i)
                den += freq[x][i][j] * 1.0 / i;
            if(i == 0 && freq[x][i][j] >= 1) zer = true;
        }
    }
    if(den)  {
        if(zer) val[x] = 0.0;
        else {
            ans += num * 1.0 * num / den;
            val[x] = num * 1.0 * num / den;
        }
    }
    else val[x] = 0.0;
}

int main() {
    int N; cin >> N;
    vector<int> A(N), B(N), P(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for(int i = 0; i < N; i++) {
        cin >> B[i];
    }
    for(int i = 0; i < N; i++) {
        cin >> P[i];
    }
    iota(par, par + N, 0);
    memset(sz, 1, sizeof(sz));
    for(int i = 0; i < N; i++) {
        X[i] = A[i];
        val[i] = P[i] * (A[i] - B[i]) * (A[i] - B[i]);
        freq[i][P[i]][B[i]] = 1;
        ans += val[i];
    }
    cout << setprecision(24);
    int Q; cin >> Q;
    while(Q--) {
        int X, Y; cin >> X >> Y;
        --X, --Y;
        merge(X, Y);
        cout << ans << "\n";
    }
}
0