zoukankan      html  css  js  c++  java
  • D

    D - Levko and Array Recovery
    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
    Submit Status
    Appoint description: 

    Description

    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:

    1. 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.
    2. 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.

    Input

    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 liri 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 liri 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.

    Output

    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.

    Sample Input

    Input
    4 5
    1 2 3 1
    2 1 2 8
    2 3 4 7
    1 1 3 3
    2 3 4 8
    Output
    YES
    4 7 4 7
    Input
    4 5
    1 2 3 1
    2 1 2 8
    2 3 4 7
    1 1 3 3
    2 3 4 13
    Output
    NO
     

    const int INF = 1000000000; const double eps = 1e-8; const int maxn = 6000; int ans[maxn]; int op[maxn]; int a[maxn]; int b[maxn]; int c[maxn]; int ans1[maxn]; int sum[maxn]; int main() { //freopen("in.txt","r",stdin); int n,m; while(cin>>n>>m) { clr(sum); repf(i,1,n) ans[i] = INF; repf(i,1,m) scanf("%d%d%d%d",&op[i],&a[i],&b[i],&c[i]); int flag = 1; repf(i,1,m) { if(op[i] == 1) { repf(j,a[i],b[i]) sum[j] += c[i]; } if(op[i] == 2) { repf(j,a[i],b[i]) { ans[j] = min(ans[j],c[i] - sum[j]); } } } repf(i,1,n) ans1[i] = ans[i]; repf(i,1,m) { if(op[i] == 1){ repf(j,a[i],b[i]) ans[j] += c[i]; } if(op[i] == 2) { int Max = -INF; repf(j,a[i],b[i]) Max = max(Max,ans[j]); if(Max == c[i]) continue; else { flag = 0; break; } } } if(flag) { cout<<"YES"<<endl; repf(i,1,n) cout<<ans1[i]<<" "; cout<<endl; }else cout<<"NO"<<endl; } return 0; }
  • 相关阅读:
    Python Day 30 网络编程 (串讲 FTP作业)
    Python Day 29 网络编程 ( socket中的一些常见方法,登录验证,socketserver模块)
    Python Day 28 网络编程 (socket远程命令执行, tcp黏包现象,以及struck模块的使用 )
    Python Day 27 网络编程 (socket udp)
    Python Day 26 网络编程 ( 网络编程基础 socket tcp)
    Python Day 25 蜥蜴串讲
    Python Day 24 面向对象进阶(双下方法 __new__ __del__ item系列 异常处理)
    Python Day 23 面向对象进阶(内置方法:反射,isinstance和issubclass,__str__和__repr__和其他双下方法)
    Python Day 21 面向对象 (面向对象的三大特性(二)继承,多态,封装,几个装饰器函数)
    aaencode:用颜文字来加密吧
  • 原文地址:https://www.cnblogs.com/DreamHighWithMe/p/3449615.html
Copyright © 2011-2022 走看看