码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces 360A(找性质)

时间:2019-07-03 00:41:46      阅读:94      评论:0      收藏:0      [点我收藏+]

标签:force   class   name   ++   puts   pre   iostream   can   put   

反思

  • 写一写可以发现上限不断更新
  • 一直在想怎么判断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]);
}

Codeforces 360A(找性质)

标签:force   class   name   ++   puts   pre   iostream   can   put   

原文地址:https://www.cnblogs.com/AlphaWA/p/11123913.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!