• Codeforces 360A(找性质)


    反思

    • 写一写可以发现上限不断更新
    • 一直在想怎么判断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]);
    }
    
  • 相关阅读:
    b_lc_第k个排列(暴搜 / 数学剪枝)
    sql语句大全(2)
    经典SQL语句大全
    存储过程格式
    经典SQL语句大全(实例)非常不错的和excel等文档实例结合的sql
    触发器MSSQL常用操作
    最好的C#学习网站
    C# 反射入门知识
    MSSQL经典语句
    一些很酷的.Net技巧
  • 原文地址:https://www.cnblogs.com/AlphaWA/p/11123913.html
Copyright © 2020-2023  润新知