CodeForces

来源:互联网 发布:网络语言 英文 编辑:程序博客网 时间:2024/06/07 10:23

C. Levko and Array Recovery
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Examples
input
4 51 2 3 12 1 2 82 3 4 71 1 3 32 3 4 8
output
YES4 7 4 7
input
4 51 2 3 12 1 2 82 3 4 71 1 3 32 3 4 13
output
NO

题意:给定序列数字的个数n和操作数m,操作1是将给定区间的所有数加某个数,操作2是求得给定区间的最大值。问可能的原序列。


思路:先把序列全部设为inf,然后把操作从后朝前遍历一遍,用操作2来限定序列中的数,用操作1来更改序列中的数。

求得序列后再从前到后遍历一遍看是否满足条件。

序列里的最大的数是1e9。。如果是用0x3f3f3f3f进行memset 最后的输出要判断。


#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <queue>#include <stack>#include <map>#include <cmath>#include <vector>#define max_ 5010#define inf 0x3f3f3f3f#define ll long longusing namespace std;struct node{    int t,l,r,w;};struct node num[max_];int n,m;int a[max_],b[max_];int main(int argc, char const *argv[]) {    cin>>n>>m;    for(int i=1;i<=m;i++)    {        cin>>num[i].t>>num[i].l>>num[i].r>>num[i].w;    }    memset(a,inf,sizeof(a));    for(int i=m;i>=1;i--)    {        if(num[i].t==1)        {            for(int j=num[i].l;j<=num[i].r;j++)            {                if(a[j]<inf)                {                    a[j]-=num[i].w;                }            }        }        else        {            for(int j=num[i].l;j<=num[i].r;j++)            {                if(a[j]>num[i].w)                {                    a[j]=num[i].w;                }            }        }    }    memcpy(b,a,sizeof(a));    int f=1;    for(int i=1;i<=m;i++)    {        if(num[i].t==1)        {            for(int j=num[i].l;j<=num[i].r;j++)            {                a[j]+=num[i].w;            }        }        else        {            int maxx=-inf;            for(int j=num[i].l;j<=num[i].r;j++)            {                if(maxx<a[j])                {                    maxx=a[j];                }            }            if(maxx!=num[i].w)            {                f=0;                break;            }        }    }    if(!f)    {        printf("NO\n" );    }    else    {        printf("YES\n" );        for(int i=1;i<=n;i++)        {            if(i!=1)            printf(" " );            if(b[i]>=1000000000)            printf("1000000000" );            else            printf("%d",b[i]);        }    }    return 0;}