QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#455874#892. Minimal CutYeahPotatoWA 1ms12528kbC++143.0kb2024-06-26 22:48:002024-06-26 22:48:01

Judging History

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

  • [2024-06-26 22:48:01]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:12528kb
  • [2024-06-26 22:48:00]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef pair <int, int> pii;
const int N = 20004, NN = N * 72;
int n, m, u, v, w, s[N], c[N], nodes, root[N], ls[NN], rs[NN], tag[NN], fa[N], siz[N];
pii tree[NN]; basic_string <pii> adj[N]; long long ans; 
struct E {
	int u, v, w;
	bool operator < (const E &e) const {
		return w > e. w;
	}
} edge[N];
pii operator + (const pii &a, const int &b) {
	return pii (a. first + b, a. second);
}
void pushup(int rt) {
	tree[rt] = min(tree[ls[rt]], tree[rs[rt]]) + tag[rt];
}
void push(int rt, int z) {
	tree[rt] = tree[rt] + z, tag[rt] += z;
}
void build(int &rt, int l, int r) {
	rt = ++ nodes;
	if (l == r) return void (tree[rt] = pii (c[l], l));
	int mid = l + r >> 1;
	build(ls[rt], l, mid), build(rs[rt], mid+1, r);
	pushup(rt);
}
void update(int lrt, int &rt, int l, int r, int x, int y, int z) {
	rt = ++ nodes, ls[rt] = ls[lrt], rs[rt] = rs[lrt], tree[rt] = tree[lrt], tag[rt] = tag[lrt];
	if (l == x && r == y) return push(rt, z);
	int mid = l + r >> 1;
	if (y <= mid) update(ls[lrt], ls[rt], l, mid, x, y, z);
	else if (x > mid) update(rs[lrt], rs[rt], mid+1, r, x, y, z);
	else update(ls[lrt], ls[rt], l, mid, x, mid, z), update(rs[lrt], rs[rt], mid+1, r, mid+1, y, z);
	pushup(rt);
}
pii query(int rt, int l, int r, int x, int y) {
	if (l == x && r == y) return tree[rt];
	int mid = l + r >> 1;
	if (y <= mid) return query(ls[rt], l, mid, x, y) + tag[rt];
	else if (x > mid) return query(rs[rt], mid+1, r, x, y) + tag[rt];
	else return min(query(ls[rt], l, mid, x, mid), query(rs[rt], mid+1, r, mid+1, y)) + tag[rt];
}
void solve(int u, int l, int r) {
	if (l > r) return ;
	pii c = min(pii (s[u], r + 1), l == r ? pii (s[r], r + 1) : r == n ? min(query(root[l], 1, n, l + 1, r), pii (:: c[l], r + 1)) : query(root[l], 1, n, l + 1, r + 1));
	edge[++m] = (E) {u, l, c. first}, solve(l, l + 1, c. second - 1), solve(u, c. second, r);
}
int find(int u) {
	return u == fa[u] ? u : fa[u] = find(fa[u]);
}
int main() {
	cin >> n >> m;
	for (int i=1; i<=m; i++)
		scanf ("%d%d%d", &u, &v, &w), adj[u] += pii (v, w), adj[v] += pii (u, w), s[u] += w, s[v] += w;
	for (int i=2; i<=n; i++) {
		c[i] = c[i-1];
		for (pii e : adj[i-1])
			c[i] += (e. first >= i ? 1 : - 1) * e. second;
	} build(root[1], 1, n);
	for (int i=2; i<=n; i++) {
		root[i] = root[i-1];
		int s = 0;
		for (pii e : adj[i-1]) {
			int j = e. first, w = e. second;
			if (j >= i) s += w, update(root[i], root[i], 1, n, i, j, - w << 1);
			else s -= w, update(root[i], root[i], 1, n, j + 1, i - 1, w << 1);
		} push(root[i], s);
	}
	pii c = query(root[1], 1, n, 2, n);
	edge[m=1] = (E) {1, n, c. first}, solve(1, 2, c. second - 1), solve(c. second, c. second + 1, n);
	for (int i=1; i<=n; i++)
		fa[i] = i, siz[i] = 1;
	sort (edge+1, edge+n);
	for (int i=1; i<n; i++) {
		int u = find(edge[i]. u), v = find(edge[i]. v);
		ans += 1ll * siz[u] * siz[v] * edge[i]. w, fa[v] = u, siz[u] += siz[v];
	} cout << (ans + 1000000000ll * n * (n - 1)) % 998244353;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 12528kb

input:

4 2
1 3 2
2 4 2

output:

21067776

result:

ok "21067776"

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 8632kb

input:

79 190
24 30 8372
16 17 3623
47 43 577
47 45 10000
50 49 9644
35 25 882
23 24 1994
54 55 7778
32 33 230
52 53 6078
5 10 8214
25 26 6829
21 22 340
67 68 6066
10 1 8104
9 10 3085
44 43 5659
33 34 5505
7 10 337
12 13 3804
5 1 4735
25 28 6650
61 60 9290
14 6 9857
38 35 6228
48 49 3076
60 59 4972
54 52 4...

output:

845080662

result:

wrong answer 1st words differ - expected: '844859152', found: '845080662'