题目地址:点击打开链接

思路:

维护每个数的上下界,先按照操作倒着求一遍,可以得到每个数的上界,再按操作正着验证一遍是否能够满足。如果都能满足的话输出上界即可。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn = 5e3+5;
const int INF = 0x3f3f3f3f/10;
int l[maxn], r[maxn], cmd[maxn][4], ans[maxn], n, m;int main(void)
{while(cin >> n >> m){for(int i = 1; i <= n; i++)l[i] = -INF, r[i] = INF;for(int i = 1; i<= m; i++)for(int j = 0; j < 4; j++)scanf("%d", &cmd[i][j]);bool ok = 1;for(int i = m; i >= 1; i--){if(cmd[i][0] == 1){for(int j = cmd[i][1]; j <= cmd[i][2]; j++){l[j] -= cmd[i][3];r[j] -= cmd[i][3];}}else{int need = 0;for(int j = cmd[i][1]; j <= cmd[i][2]; j++){if(l[j] > cmd[i][3]){ok = 0;break;}else{if(r[j] >= cmd[i][3]) r[j] = cmd[i][3], need = 1;}}if(!need) ok = 0;}
//            for(int i = 1; i <= n; i++)
//            printf("%d : %d %d\n", i, l[i], r[i]);
//            printf("\n");}if(!ok) puts("NO");else{//puts("YES");bool ok = 1;for(int i = 1; i <= n; i++)ans[i] = r[i];for(int i = 1; i <= m; i++){if(cmd[i][0] == 1){for(int j = cmd[i][1]; j <= cmd[i][2]; j++)ans[j] += cmd[i][3];}else{int need = 0;for(int j = cmd[i][1]; j <= cmd[i][2]; j++)if(ans[j] >= cmd[i][3]) need = 1;if(!need) ok = 0;}}if(!ok) puts("NO");else{puts("YES");for(int i = 1; i <= n;i++)printf("%d%c", r[i], i==n ? '\n' : ' ');}}}return 0;
}

CodeForces 360A - Levko and Array Recovery (模拟)相关推荐

  1. CodeForces 360A - Levko and Array Recovery (思维)

    题意: 给定一个序列,然后对其进行两种操作 1   L R W   代表从 a[L ] 到a[R] 全部加上W 2   L R W  代表从  a[L] 到 a[R] 中最大值为 W 问是否存在一个序 ...

  2. CodeForces 360A - Levko and Array Recovery【动规】

    题意:一道已知操作求原始数组的题目: 分析:求出每个位置初始时可能的最小值...然后再判断是否合法即可: 疑问之处:为什么a数组初始要给10^9(原始数组的最大范围),而不能是inf? AC代码: # ...

  3. CodeForces 360A - Levko and Array Recovery 给出操作求原始数列

    题意: 对一个数列有这么两个操作 1.(1,l,r,p)..将区间[l,r]所有数都加上p 2.(2,l,r,m).求出区间[l,r]的最大值为m 现在告诉这么一些操作(<5000个)...问能 ...

  4. CodeForces 1514A Perfectly Imperfect Array

    CodeForces 1514A Perfectly Imperfect Array 题意: 给你n个数,是否存在一个数不是平方数 题解: 先开方,转int,判断是否等于平方 代码: #include ...

  5. Codeforces Round #249 (Div. 2) (模拟)

    Codeforces Round #249 (Div. 2) (模拟) C. Cardiogram time limit per test 1 second memory limit per test ...

  6. 【CodeForces - 361D】Levko and Array (二分,dp)

    题干: Levko has an array that consists of integers: a1, a2, ... , an. But he doesn't like this array a ...

  7. codeforces 361 D. Levko and Array(dp+二分)

    题目链接:http://codeforces.com/contest/361/problem/D 题意:最多可以修改K次数字,每次修改一个数字变成任意值,C=max(a[i+1]-a[i]):求操作之 ...

  8. Codeforces Round #304 C(Div. 2)(模拟)

    题目链接: http://codeforces.com/problemset/problem/546/C 题意: 总共有n张牌,1手中有k1张分别为:x1, x2, x3, ..xk1,2手中有k2张 ...

  9. Educational Codeforces Round 11A. Co-prime Array 数学

    地址:http://codeforces.com/contest/660/problem/A 题目: A. Co-prime Array time limit per test 1 second me ...

最新文章

  1. 社会生活中常用的14条著名法则
  2. IE6下fixed失效的解决方法
  3. iOS 关于.tbd与.dylib用法
  4. 为什么美国财媒IBD力推网易为第1强股?
  5. 无法加载 DLL“oramts.dll”: 找不到指定的模块。 (异常来自 HRESULT:0x8007007E)
  6. unity深度查找某个子物体和遍历所有子物体方法
  7. 红旗linux 装xp,XP下硬盘安装红旗LINUX
  8. Oracle VM + Windows2003 Server 配置
  9. 基于统计的压缩算法:游程编码
  10. 在IDEA中实战Git-branch入门
  11. 遗传算法导论(转载)
  12. 微信小程序报错:Unhandled promise rejection TypeError: WebAssembly.instantiate(): Argument 0 must be a buffe
  13. C语言要点系统复习三:scanf读取缓冲区的那些事
  14. 换个角度理解Android的AIDL原理
  15. 火车头采集器采集教程
  16. 清华牛人总结的数据分析笔记
  17. 极速闪存IBM FlashSystem一马当先
  18. MySQL数据库下载与安装详细教程
  19. 建造者(Builder)模式
  20. 关于 SecureFx传输远程服务器中文显示乱码 的解决方法

热门文章

  1. 谷歌叫你来找bug!不会的还包教!
  2. 可重复读(Repeatable read)能防住幻读吗?
  3. [Google Guava]--Ordering类
  4. 双屏显示复制模式显示正常扩展模式提示分辨率超出范围
  5. crypt模块的使用
  6. The Sound Of Silence
  7. 七种武器——.NET
  8. MySQL-MVCC机制
  9. Oracle账户被锁住,解锁
  10. 十年,英方软件的变与不变