QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#360498#6350. MITGlaciaTL 125ms8652kbC++232.3kb2024-03-21 20:23:412024-03-21 20:23:41

Judging History

你现在查看的是最新测评结果

  • [2024-03-21 20:23:41]
  • 评测
  • 测评结果:TL
  • 用时:125ms
  • 内存:8652kb
  • [2024-03-21 20:23:41]
  • 提交

answer

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

#define int long long

int n, u, v, w, cnt[100471], ans[100471];
vector<pair<int, int>> G[100471], V;
pair<tuple<int, int, int>, tuple<int, int, int>> val[100471];

void dfs(int u, int f, int x, int y) {
	V.emplace_back(y, x);
	for (auto [v, w] : G[u]) {
		if (v != f) {
			dfs(v, u, x, y + w);
		}
	}
}

pair<tuple<int, int, int>, tuple<int, int, int>> merge(pair<tuple<int, int, int>, tuple<int, int, int>> a, pair<tuple<int, int, int>, tuple<int, int, int>> b) {
	if (a.first < b.first) {
		swap(a, b);
	}
	return make_pair(a.first, get<2>(b.first) && get<2>(b.first) != get<2>(a.first) && b.first > a.second ? b.first : get<2>(a.second) && a.second > b.second ? a.second : b.second);
}

void build(int l, int r, int o) {
	if (l == r) {
		val[o] = {{V[l].first, l, V[l].second}, {-1, n, 0}};
		return;
	}
	int mid = (l + r) / 2;
	build(l, mid, o << 1);
	build(mid + 1, r, o << 1 | 1);
	val[o] = merge(val[o << 1], val[o << 1 | 1]);
}

void remove(int x, int l, int r, int o) {
	if (l == r) {
		val[o] = {{-1, n, 0}, {-1, n, 0}};
		return;
	}
	int mid = (l + r) / 2;
	if (x <= mid) {
		remove(x, l, mid, o << 1);
	} else {
		remove(x, mid + 1, r, o << 1 | 1);
	}
	val[o] = merge(val[o << 1], val[o << 1 | 1]);
}

pair<tuple<int, int, int>, tuple<int, int, int>> query(int ll, int rr, int l, int r, int o) {
	if (ll <= l && r <= rr) {
		return val[o];
	} else if (ll <= r && l <= rr) {
		int mid = (l + r) / 2;
		return merge(query(ll, rr, l, mid, o << 1), query(ll, rr, mid + 1, r, o << 1 | 1));
	} else {
		return {{-1, n, 0}, {-1, n, 0}};
	}
}

signed main() {
	scanf("%lld", &n);
	for (int i = 1; i < n; i++) {
		scanf("%lld%lld%lld", &u, &v, &w);
		G[u].emplace_back(v, w);
		G[v].emplace_back(u, w);
	}
	for (int i = 1; i <= n; i++) {
		V = {{0, i}};
		for (auto [v, w] : G[i]) {
			dfs(v, i, v, w);
		}
		sort(V.begin(), V.end(), greater<pair<int, int>>());
		memset(cnt, 0, sizeof(cnt));
		build(0, n - 1, 1);
		int res = 0, pos = 0;
		for (int j = 0; j < n; j++) {
			auto [d, u, v] = (cnt[get<2>(val[1].first)] > j / 2 ? val[1].second : val[1].first);
			if (u == n) {
				break;
			}
			cnt[v]++;
			res += d;
			remove(u, 0, n - 1, 1);
			ans[j + 1] = max(ans[j + 1], res);
		}
	}
	for (int i = 2; i <= n; i += 2) {
		printf("%lld ", ans[i]);
	}
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 6604kb

input:

7
1 3 99
2 3 82
3 4 4
4 5 43
5 6 5
4 7 3

output:

181 280 287 

result:

ok 3 number(s): "181 280 287"

Test #2:

score: 0
Accepted
time: 125ms
memory: 8652kb

input:

1000
328 12 58771429
881 504 17030494
847 622 20805817
12 922 58532669
879 929 52585738
495 726 27873950
855 17 37971674
797 941 76999719
702 610 719916
479 127 97829887
731 557 55300256
282 615 88802280
651 318 64099880
540 51 6547869
896 54 87823596
674 879 80674008
77 691 54802376
193 851 7869172...

output:

48829042195 97562386542 146216474947 194713456438 243120633399 291394542517 339657517459 387785045812 435787622310 483691355869 531476208289 579153483709 626793764008 674259794140 721617453738 768862531418 816032104456 863044440224 909960999950 956790589086 1003491332151 1050093110804 1096582356539 ...

result:

ok 500 numbers

Test #3:

score: 0
Accepted
time: 68ms
memory: 6116kb

input:

1000
739 878 29520635
133 940 5021186
160 908 26446479
441 122 80604853
539 396 95959331
635 860 46393560
387 172 58313059
53 442 65841670
121 159 59547874
35 264 28494605
269 78 29571243
436 384 89754669
619 47 52195144
57 336 95094232
936 419 88183176
877 634 14912042
47 100 57449297
533 101 61185...

output:

1335958866 2626054407 3904456915 5174845834 6437211717 7689455676 8928545787 10163335876 11395869036 12622043944 13839303826 15049898576 16256276325 17459646468 18659090162 19856778178 21048658276 22239285858 23421421030 24597109238 25772007715 26944410577 28111355238 29275440829 30439025973 3160110...

result:

ok 500 numbers

Test #4:

score: -100
Time Limit Exceeded

input:

10000
8832 9937 83287693
1229 3010 26805846
5184 8703 32371496
5692 201 90600077
7857 7922 2427036
6991 1815 55936149
9126 8434 96181780
2395 5238 99604883
3721 3882 32707216
6961 5616 4158592
479 2786 52279400
9395 164 84498120
9470 462 16429465
8303 9717 36203661
4462 3119 77535638
9010 5633 83602...

output:


result: