A. Levko and Array Recovery----思维题
来源:互联网 发布:黑马java基础班测试题 编辑:程序博客网 时间:2024/05/16 08:55
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 the i-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 and mi (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 integers a1, 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
题目链接:http://codeforces.com/contest/360/problem/A
题目的意思是说对于一个序列有两个操作:
1.(1,l,r,p)..将区间[l,r]所有数都加上p
2.(2,l,r,m).求出区间[l,r]的最大值为m
现在给你这个操作,问你时候能够找到原序列,任意输出一个正确答案即可。
这个题我没有想出来,看了大牛的题解。
这个题就是求出每个位置初始时可能的最小值,然后判断是否合法。
代码:
#include <cstdio>#include <iostream>#include <cstring>#define inf 1000000007using namespace std;struct node{ int t,l,r,m;} op[5010];int a[5010],b[5010],n,m;bool solve(){ int p,i,k; for (i=1;i<=n;i++){ a[i]=1000000000; } memset(b,0,sizeof(b)); for (p=1;p<=m;p++){ if (op[p].t==1) for (i=op[p].l;i<=op[p].r;i++) b[i]+=op[p].m; else for (i=op[p].l;i<=op[p].r;i++) a[i]=min(a[i],op[p].m-b[i]); } memset(b,0,sizeof(b)); for (p=1;p<=m;p++){ if (op[p].t==1) for (i=op[p].l; i<=op[p].r; i++) b[i]+=op[p].m; else{ k=-inf; for(i=op[p].l;i<=op[p].r;i++) k=max(k,a[i]+b[i]); if(k!=op[p].m) return false; } } return true;}int main(){ int i; scanf("%d%d",&n,&m); for (i=1; i<=m; i++){ scanf("%d%d%d%d",&op[i].t,&op[i].l,&op[i].r,&op[i].m); } if (!solve()){ printf("NO\n"); } else{ printf("YES\n"); for (i=1;i<=n;i++) printf("%d ",a[i]); cout<<endl; } return 0;}
- A. Levko and Array Recovery----思维题
- CodeForces 360A - Levko and Array Recovery (思维)
- CodeForces 360A - Levko and Array Recovery【动规】
- 记某次codeforces考试 A. Levko and Array Recovery
- Codeforces Round #210 (Div. 2) C. Levko and Array Recovery && Codeforces 360 A 详解(思维+维护理论值)
- CodeForces 360A - Levko and Array Recovery 给出操作求原始数列
- CF-Codeforces Round #210 (Div. 1)-A-Levko and Array Recovery
- CF_360B Levko and Array
- A. Levko and Table
- Codeforces 361D Levko and Array【二分+dp】好题!
- Codeforces Round #210 (Div. 1) B. Levko and Array(dp 思维)
- Codeforces 360B Levko and Array
- Codeforces #360B: Levko and Array 题解
- B. Levko and Array----二分答案
- Codeforces 361A Levko and Table
- [Codeforces] 361A - Levko and Table
- codeforces D. Levko and Array(二分加dp) 挺好的一个题
- CF 360B - Levko and Array (二分+dp)
- d3.js-坐标轴
- 找一个数组中出现奇数次的那个数
- CAP原则和BASE理论及ACID
- SirDigit CMake 手册详解(二十二)
- 大话数据结构 code 第七章 10关键路径_CriticalPath
- A. Levko and Array Recovery----思维题
- 理解高并发(10).线程通信之_线程中断技术
- Eclipse的基本用法
- [LeetCode] 345. Reverse Vowels of a String
- java中Integer值比较不注意的问题
- LeetCode中应用异或操作的几个题目
- ACM小白入门
- 德国创意ab
- 【Node.js-6】consolidate模板引擎集成、router路由介绍