CodeForces
来源:互联网 发布:软件测试的思路 编辑:程序博客网 时间:2024/04/24 04:47
Levko loves array a1, a2, ... , an, consisting of integers, very much. That is why Levko is playing with array a, performing all sorts of operations with it. Each operation Levko performs is of one of two types:
- Increase all elements from li to ri by di. In other words, perform assignments aj = aj + di for all j that meet the inequation li ≤ j ≤ ri.
- Find the maximum of elements from li to ri. That is, calculate the value .
Sadly, Levko has recently lost his array. Fortunately, Levko has records of all operations he has performed on array a. Help Levko, given the operation records, find at least one suitable array. The results of all operations for the given array must coincide with the record results. Levko clearly remembers that all numbers in his array didn't exceed 109 in their absolute value, so he asks you to find such an array.
The first line contains two integers n and m (1 ≤ n, m ≤ 5000) — the size of the array and the number of operations in Levko's records, correspondingly.
Next m lines describe the operations, the i-th line describes thei-th operation. The first integer in the i-th line is integer ti(1 ≤ ti ≤ 2) that describes the operation type. If ti = 1, then it is followed by three integers li, ri and di (1 ≤ li ≤ ri ≤ n, - 104 ≤ di ≤ 104) — the description of the operation of the first type. If ti = 2, then it is followed by three integers li, ri andmi (1 ≤ li ≤ ri ≤ n, - 5·107 ≤ mi ≤ 5·107) — the description of the operation of the second type.
The operations are given in the order Levko performed them on his array.
In the first line print "YES" (without the quotes), if the solution exists and "NO" (without the quotes) otherwise.
If the solution exists, then on the second line print n integersa1, a2, ... , an (|ai| ≤ 109) — the recovered array.
4 51 2 3 12 1 2 82 3 4 71 1 3 32 3 4 8
YES4 7 4 7
4 51 2 3 12 1 2 82 3 4 71 1 3 32 3 4 13
NO
思路: 这个题其实想好了挺好实现的,我们可以将所有的数据初始化为inf(10^9),
先从尾往后跑判断每个位置可能存在的最大值,然后在从后往前跑判断是否满足条件
#include<stdio.h>#include<math.h>#include<string.h>#define inf 1000000000using namespace std;struct node{int l,r,f,w;}q[5555];int n,m,ans1[5555],ans2[5555];int main(){scanf("%d%d",&n,&m);for(int i=1;i<=m;i++)scanf("%d%d%d%d",&q[i].f,&q[i].l,&q[i].r,&q[i].w);for(int i=1;i<=n;i++)ans1[i]=inf;for(int i=m;i>=1;i--){if(q[i].f==1){for(int j=q[i].l;j<=q[i].r;j++){if(ans1[j]!=inf)ans1[j]-=q[i].w;}}else{for(int j=q[i].l;j<=q[i].r;j++){if(ans1[j]>q[i].w)ans1[j]=q[i].w;}}}for(int i=1;i<=n;i++)ans2[i]=ans1[i];int flag=1;for(int i=1;i<=m;i++){if(q[i].f==1){for(int j=q[i].l;j<=q[i].r;j++){ans1[j]+=q[i].w;}}else{int maxn=-inf;for(int j=q[i].l;j<=q[i].r;j++){if(ans1[j]>maxn)maxn=ans1[j];}if(maxn!=q[i].w){flag=0;break;}}}if(!flag)printf("NO\n");else{printf("YES\n");printf("%d",ans2[1]);for(int j=2;j<=n;j++)printf(" %d",ans2[j]);printf("\n");}return 0;}
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- 笔记——Java之抽象类
- image scale和size的关系与SDScaledImageForKey
- 设计模式学习笔记---观察者模式Observer pattern(Java版)
- 字符串匹配
- 用Criteria进行模糊查询实现简单的搜索功能
- CodeForces
- leetcode---Product of Array Except Self
- 向上转型和向下转型
- 有向图的欧拉道路 UVA
- Leetcode题解:513. Find Bottom Left Tree Value
- RHEL6.5 LVM硬盘管理
- leetcode508
- 1091. Acute Stroke (30)[bfs广度优先搜索+种子填充]
- 64位MinGW和MSYS的安装