結果

問題 No.1365 [Cherry 1st Tune] Whose Fault?
ユーザー iaNTUiaNTU
提出日時 2021-01-22 04:39:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 363 ms / 2,000 ms
コード長 1,252 bytes
コンパイル時間 2,622 ms
コンパイル使用メモリ 198,832 KB
実行使用メモリ 11,348 KB
最終ジャッジ日時 2023-08-28 11:22:10
合計ジャッジ時間 25,431 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,192 KB
testcase_01 AC 2 ms
4,948 KB
testcase_02 AC 2 ms
5,016 KB
testcase_03 AC 2 ms
4,760 KB
testcase_04 AC 2 ms
5,008 KB
testcase_05 AC 2 ms
5,012 KB
testcase_06 AC 2 ms
4,948 KB
testcase_07 AC 2 ms
5,012 KB
testcase_08 AC 2 ms
5,012 KB
testcase_09 AC 1 ms
5,008 KB
testcase_10 AC 2 ms
5,016 KB
testcase_11 AC 2 ms
5,068 KB
testcase_12 AC 2 ms
4,952 KB
testcase_13 AC 34 ms
5,008 KB
testcase_14 AC 23 ms
9,988 KB
testcase_15 AC 7 ms
9,784 KB
testcase_16 AC 6 ms
9,756 KB
testcase_17 AC 20 ms
9,860 KB
testcase_18 AC 13 ms
9,832 KB
testcase_19 AC 32 ms
9,832 KB
testcase_20 AC 19 ms
9,716 KB
testcase_21 AC 30 ms
9,696 KB
testcase_22 AC 24 ms
9,912 KB
testcase_23 AC 69 ms
10,572 KB
testcase_24 AC 146 ms
11,076 KB
testcase_25 AC 297 ms
11,116 KB
testcase_26 AC 202 ms
10,880 KB
testcase_27 AC 240 ms
10,220 KB
testcase_28 AC 102 ms
9,928 KB
testcase_29 AC 84 ms
10,268 KB
testcase_30 AC 363 ms
11,064 KB
testcase_31 AC 319 ms
11,248 KB
testcase_32 AC 181 ms
11,256 KB
testcase_33 AC 290 ms
10,536 KB
testcase_34 AC 227 ms
10,376 KB
testcase_35 AC 131 ms
10,904 KB
testcase_36 AC 272 ms
11,108 KB
testcase_37 AC 58 ms
10,140 KB
testcase_38 AC 74 ms
10,968 KB
testcase_39 AC 345 ms
10,828 KB
testcase_40 AC 342 ms
10,924 KB
testcase_41 AC 258 ms
10,912 KB
testcase_42 AC 235 ms
10,244 KB
testcase_43 AC 3 ms
9,580 KB
testcase_44 AC 84 ms
11,348 KB
testcase_45 AC 109 ms
9,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
constexpr int kN = int(2E5 + 10);

int union_find[kN], a[kN], b[kN], p[kN], x[kN], y[kN];
long long int sum_a[kN], sum_b[kN];
double ans, sum_of_inverse_p[kN];

double Cal(int n) {
	double x = fabs(sum_a[n] - sum_b[n]);
	return x * x / sum_of_inverse_p[n];
}

int Find(int n) {return n == union_find[n] ? n : union_find[n] = Find(union_find[n]);}
void Merge(int l, int r) {
	l = Find(l), r = Find(r);
	if (l != r) {
		ans -= Cal(l);
		ans -= Cal(r);
		union_find[r] = l;
		sum_a[l] += sum_a[r];
		sum_b[l] += sum_b[r];
		sum_of_inverse_p[l] += sum_of_inverse_p[r];
		ans += Cal(l);
	}
	return ;
}

int main() {
	int n, q;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
	for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
	scanf("%d", &q);
	for (int i = 1; i <= q; i++) scanf("%d%d", &x[i], &y[i]);

	for (int i = 1; i <= n; i++) sum_a[i] = a[i];
	for (int i = 1; i <= n; i++) sum_b[i] = b[i];
	for (int i = 1; i <= n; i++) sum_of_inverse_p[i] = 1.0 / p[i];
	for (int i = 1; i <= n; i++) union_find[i] = i;
	for (int i = 1; i <= n; i++) ans += Cal(i);

	for (int i = 1; i <= q; i++) {
		Merge(x[i], y[i]);
		printf("%.20lf\n", ans);
	}
}
0