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; }
  • 相关阅读:
    ant的安装和配置
    jmeter3.x的jtx文件解析
    爬虫:网页里元素的xpath结构,scrapy不一定就找的到
    如何实现新浪微博功能:关注某个的发布信息,自动点赞和转发
    性能测试各个指标的含义
    python模块相关
    curl的用法
    第十八章 Python批量管理主机(paramiko、fabric与pexpect)
    死锁产生的原因和解锁的方法
    读写分离死锁解决方案、事务发布死锁解决方案、发布订阅死锁解决方案
  • 原文地址:https://www.cnblogs.com/DreamHighWithMe/p/3449615.html
Copyright © 2011-2022 走看看