比赛 2026.8.28 评测结果 AAAAAWWWWW
题目名称 无法拒绝孤独的她 最终得分 50
用户昵称 赵飞羽 运行时间 2.360 s
代码语言 C++ 内存使用 15.82 MiB
提交时间 2026-08-28 10:51:00
显示代码纯文本
#include <bits/stdc++.h>
#define int long long
using namespace std;

constexpr int N = 500010;
int n, q, a[N], b[N], c[N], t[N], p, x, y, z, cnt;
struct node{
	int p, x, y, z;
} e[N];

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	freopen("cantrefuse.in", "r", stdin);
	freopen("cantrefuse.out", "w", stdout);
	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];
	if (n <= 5000 && q <= 5000) {
		while (q--) {
			cin >> p >> x >> y >> z;
			a[p] = x, b[p] = y, c[p] = z;
			cnt = 0;
			for (int i = 1; i <= n; i++) t[i] = a[i];
			for (int i = 1; i <= n; i++) {
				cnt += min(t[i], b[i]);
				t[i] = max(0LL, t[i] - b[i]);
				t[i+1] += min(c[i], t[i]);
			}
			cout << cnt << "\n";
		}
	} else {
		int flg1 = 0, flg2 = 0, flg3 = 0;
		for (int i = 1; i <= q; i++) {
			cin >> e[i].p >> e[i].x >> e[i].y >> e[i].z;
			if (e[i].x != 0) flg1 = 1;
			if (e[i].y != 0) flg2 = 1;
			if (e[i].z != 0) flg3 = 1;
		}
		if (flg1 == 0 || flg2 == 0) while (q--) cout << 0 << "\n";
		else {
			cnt = 0;
			for (int i = 1; i <= n; i++) cnt += min(a[i], b[i]);
			for (int i = 1; i <= q; i++) {
				p = e[i].p;
				cnt -= min(a[p], b[p]);
				a[p] = e[i].x;
				b[p] = e[i].y;
				cnt += min(a[p], b[p]);
				cout << cnt << "\n";
			}
		}
	}
	return 0;
}