反思
- 写一写可以发现上限不断更新
- 一直在想怎么判断NO,刻板拘泥于错误的模型,想要像往常一样贪心地、读入当前值就能判断会不会NO,实际上只要构造完以后,最后把所有操作重新跑一遍看会不会冲突即可判断NO
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 5005;
int n, m, a[maxn];
int op[maxn], l[maxn], r[maxn], d[maxn];
int maxval[maxn], add[maxn];
int main() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++)
maxval[i] = 1e9;
for (int i = 1; i <= m; i++) {
scanf("%d %d %d %d", &op[i], &l[i], &r[i], &d[i]);
if (op[i] == 1) {
for (int j = l[i]; j <= r[i]; j++)
add[j] += d[i];
} else {
for (int j = l[i]; j <= r[i]; j++)
maxval[j] = min(maxval[j], d[i] - add[j]);
}
}
for (int i = 1; i <= n; i++)
a[i] = maxval[i];
for (int i = 1; i <= m; i++) {
if (op[i] == 1) {
for (int j = l[i]; j <= r[i]; j++)
a[j] += d[i];
} else {
int minn = -1e9;
for (int j = l[i]; j <= r[i]; j++)
minn = max(minn, a[j]);
if (minn != d[i]) return puts("NO");
}
}
puts("YES");
for (int i = 1; i <= n; i++)
printf("%d ", maxval[i]);
}