| 记录编号 |
618327 |
评测结果 |
AAAAAAAAAA |
| 题目名称 |
4465.无法拒绝孤独的她 |
最终得分 |
100 |
| 用户昵称 |
RpUtl |
是否通过 |
通过 |
| 代码语言 |
C++ |
运行时间 |
4.103 s |
| 提交时间 |
2026-08-28 20:33:24 |
内存使用 |
29.96 MiB |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e5 + 10;
const ll inf = 1e18 + 10;
ll a[N], b[N], c[N];
struct Data {
int l, r;
ll flow, nowto, rest, restto;
void init(int x) {
l = r = x;
flow = min(b[x], a[x]);
nowto = max(0ll, a[x] - b[x]);
rest = max(0ll, b[x] - a[x]);
restto = inf;
}
} w;
ll can, incf, incto, ncan, nvrest;
Data operator + (const Data &u, const Data &v) {
w.l = u.l, w.r = v.r;
can = min(c[u.r], u.nowto), incf = min(can, v.rest);
incto = min(v.restto, max(can - v.rest, 0ll));
w.flow = u.flow + v.flow + incf, w.nowto = v.nowto + incto;
w.rest = u.rest + min({u.restto, c[u.r] - can, v.rest - incf});
ncan = min(u.restto, c[u.r] - can), nvrest = v.rest - incf;
w.restto = min(v.restto - incto, max(ncan - nvrest, 0ll));
return w;
}
struct sgt {
Data val[N << 2];
#define ls (p << 1)
#define rs (p << 1 | 1)
void pushup(int p) {
val[p] = val[ls] + val[rs];
}
void upd(int p, int l, int r, int x) {
if (l == r) {
val[p].init(x);
} else {
int mid = (l + r) >> 1;
if (x <= mid) upd(ls, l, mid, x);
if (x > mid) upd(rs, mid + 1, r, x);
pushup(p);
}
}
void build(int p, int l, int r) {
if (l == r) {
val[p].init(l);
} else {
int mid = (l + r) >> 1;
build(ls, l, mid);
build(rs, mid + 1, r);
pushup(p);
}
}
} T;
int n, q;
int main() {
freopen("cantrefuse.in", "r", stdin);
freopen("cantrefuse.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n >> q;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
for (int i = 1; i < n; i++) cin >> c[i];
T.build(1, 1, n);
ll p, x, y, z;
while (q--) {
cin >> p >> x >> y >> z;
a[p] = x, b[p] = y, c[p] = z;
T.upd(1, 1, n, p);
cout << T.val[1].flow << '\n';
}
return 0;
}