CF_Educational_Round_34_G

Yet Another Maxflow Problem

题目传送门

对于点$A_{i}$,它的流量有两种,一种是通过横边流向$B$,一种是流向$A_{i + 1}$.
如果以$A_{i}$为分界点,那么答案就是$A$中$\leq i$的点通过横边流出的流量加上流向$A_{i + 1}$的流量.
对于每个$A_{i}$,我们假设它流向$A_{i + 1}$是满流,然后通过线段树维护出$A$中$\leq i$的点通过横边实际流出的最大流量,令这两部分和为$c_{i}$.
因为$A_{i}$实际流向$A_{i + 1}$的流量是$A_{i}->A_{i+1}$的边权和$A$中$> i$的点通过横边流出的流量中的最小值,所以答案就是$min(c_{i})$
然后每次修改边权的时候只需要用线段树维护单点修改即可.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//created by missever
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 5;
int ca[maxn];
LL f[maxn * 4], ly[maxn * 4], cb[maxn], cc[maxn];
struct edge {
int u, v, w;
} g[maxn];
bool cmp(const edge &a, const edge &b) {
return a.u < b.u;
}
void push_down(int t) {
if(ly[t]) {
f[t << 1] += ly[t];
ly[t << 1] += ly[t];
f[t << 1 | 1] += ly[t];
ly[t << 1 | 1] += ly[t];
ly[t] = 0;
}
}
void build(int t, int l, int r, LL val[]) {
ly[t] = 0;
if(l == r) {
f[t] = val[l];
return;
}
int mid = (l + r) >> 1;
build(t << 1, l, mid, val);
build(t << 1 | 1, mid + 1, r, val);
f[t] = min(f[t << 1], f[t << 1 | 1]);
}
void update(int t, int l, int r, int ll, int rr, LL v) {
if(ll <= l && r <= rr) {
f[t] += v;
ly[t] += v;
return;
}
int mid = (l + r) >> 1;
push_down(t);
if(ll <= mid) update(t << 1, l, mid, ll, rr, v);
if(rr > mid) update(t << 1 | 1, mid + 1, r, ll, rr, v);
f[t] = min(f[t << 1], f[t << 1 | 1]);
}
int main() {
#ifdef CX_TEST
freopen("E:\\program--GG\\test_in.txt", "r", stdin);
#endif
int n, m, q, i, j;
scanf("%d%d%d", &n, &m, &q);
for(i = 1; i < n; i++) scanf("%d%lld", &ca[i], &cb[i + 1]);
build(1, 1, n, cb);
for(i = 0; i < m; i++) scanf("%d%d%d", &g[i].u, &g[i].v, &g[i].w);
sort(g, g + m, cmp);
for(i = 1, j = 0; i <= n; i++) {
while(j < m && g[j].u == i) {
update(1, 1, n, 1, g[j].v, g[j].w);
j++;
}
cc[i] = f[1] + ca[i];
}
build(1, 1, n, cc);
printf("%lld\n", f[1]);
while(q--) {
scanf("%d%d", &i, &j);
update(1, 1, n, i, i, j - ca[i]);
ca[i] = j;
printf("%lld\n", f[1]);
}
return 0;
}