http://codeforces.com/contest/361/problem/C

这道题倒着一次,然后正着一次,在正着的一次的时候判断合不合法就可以。

 #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int inf=; int p[],ans[];
int t[],l[],r[],d[];
int n,m;
int flag; int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=; i<=n; i++)
{
ans[i]=inf;
}
for(int i=; i<m; i++)
{
scanf("%d%d%d%d",&t[i],&l[i],&r[i],&d[i]);
}
for(int i=m-; i>=; i--)
{
if(t[i]==)
{
for(int j=l[i]; j<=r[i]; j++)
{
ans[j]-=d[i];
}
}
else if(t[i]==)
{
for(int j=l[i]; j<=r[i]; j++)
{
ans[j]=min(ans[j],d[i]);
}
}
}
for(int i=; i<=n; i++)
{
p[i]=ans[i];
}
bool flag1=false;
for(int i=; i<m; i++)
{
if(t[i]==)
{
for(int j=l[i]; j<=r[i]; j++)
{
p[j]+=d[i];
}
}
else if(t[i]==)
{
flag=;
for(int j=l[i]; j<=r[i]; j++)
{
if(p[j]==d[i]) flag=;
else if(p[j]>d[i])
{
flag1=true;
break;
}
}
if(flag!=)
{
flag1=true;
break;
}
}
}
if(flag1) printf("NO\n");
else
{
printf("YES\n");
for(int i=; i<=n; i++)
{
if(i==)
printf("%d",ans[i]);
else printf(" %d",ans[i]);
}
printf("\n");
}
}
return ;
}

cf C. Levko and Array Recovery的更多相关文章

  1. [codeforces 360]A. Levko and Array Recovery

    [codeforces 360]A. Levko and Array Recovery 试题描述 Levko loves array a1, a2, ... , an, consisting of i ...

  2. Codeforces Round #210 (Div. 2) C. Levko and Array Recovery

    题目链接 线段树的逆过程,想了老一会,然后发现应该是包含区间对存在有影响,就不知怎么做了...然后尚大神,说,So easy,你要倒着来,然后再正着来,判断是不是合法就行了.然后我乱写了写,就过了.数 ...

  3. cf D. Levko and Array

    http://codeforces.com/contest/361/problem/D 用二分搜索相邻两个数的差的绝对值,然后用dp记录数改变的次数.dp[i]表示在i之前改变的次数,如果|a[i]- ...

  4. codeforces 361 C. Levko and Array Recovery(暴力+思维)

    题目链接:http://codeforces.com/contest/361/problem/C 题意:对一个数列有这么两个操作 1.(1,l,r,p)..将区间[l,r]所有数都加上p 2.(2,l ...

  5. CF360B Levko and Array (二分查找+DP)

    链接:CF360B 题目: B. Levko and Array time limit per test 2 seconds memory limit per test 256 megabytes i ...

  6. Codeforces 361D Levko and Array(二分)(DP)

    Levko and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  7. 有意思的DP(CF360B Levko and Array)

    刚才面试了一个蛮有意思的DP题目,脑子断片,没写出来,不过早上状态还是蛮好的 一个长度为n的序列最多改变k次,使相邻两数之差绝对值的最大值最小 三维的dp我先尝试写一下 Codeforces 360B ...

  8. CodeForces - 361D Levko and Array

    Discription Levko has an array that consists of integers: a1, a2, ... , an. But he doesn’t like this ...

  9. CF 1008C Reorder the Array

    You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it ...

随机推荐

  1. 【HDOJ】2526 浪漫手机

    字符串大水题. #include <cstdio> #include <cstring> #include <cstdlib> #define MAXN 105 t ...

  2. http调试工具,linux调试工具

    charles Linux下Web性能压力测试工具http_load linux 下的socket 调试工具 netcat Linux下四款Web服务器压力测试工具(http_load.webbenc ...

  3. 【转】Linux中断处理学习笔记

    原文网址:http://www.cnblogs.com/GT_Andy/archive/2011/06/21/2086100.html 1.Linux中断的注册与释放: 在<linux/inte ...

  4. CSS3/HTML5实现漂亮的分步骤注册登录表单

    分步骤的登录注册表单现在也比较多,主要是能提高用户体验,用户可以有选择性的填写相应的表单信息,不至于让用户看到一堆表单望而却步.今天和大家分享的就是一款基于HTML5和CSS3的分步骤注册登录表单,外 ...

  5. Python 2 到 Python 3的变化

    Python 2.x到Python 3.x变化还是挺大的,具体的变化,参考官方文档: https://docs.python.org/3.0/whatsnew/3.0.html

  6. android开发常用组件(库)推荐

    版本兼容:官方 support 全家桶 网络请求:Android-Async-Http.Retrofit.OkHttp.Volley图片加载:Glide 和 Universal-Image-Loade ...

  7. 听说每天都要写随笔,word哥~

    今天主要学习了html的基本知识,进制的转换,无序列表,有序列表和表格,都是很基本的东西,然后自己自习了表单. <!DOCTYPE html PUBLIC "-//W3C//DTD X ...

  8. css让div水平垂直居中

    示例1: .div1{ width:200px; height:300px; border:1px solid #000; position: relative; } .div2{ width: 40 ...

  9. Ubunte 11.4 下安装 SSH遇到的问题

    第一次安装报了一堆错,主要是也http 404 not found之类的,搜索了一番怀疑是apt的source list的问题. 网上找到一份替换之,我用的是搜狐的服务器.网址如下: http://b ...

  10. (转)介绍几个C#正则表达式工具

    推荐三个C#正则表达式工具,理由如下 第一个C#正则表达式工具,REGEX 这个C#正则表达式工具优点是中文的,提供了一些示例 第二个C#正则表达式工具,REGEXBUDDY 这是一个真正专业的REG ...