cf C. Levko and Array Recovery
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的更多相关文章
- [codeforces 360]A. Levko and Array Recovery
[codeforces 360]A. Levko and Array Recovery 试题描述 Levko loves array a1, a2, ... , an, consisting of i ...
- Codeforces Round #210 (Div. 2) C. Levko and Array Recovery
题目链接 线段树的逆过程,想了老一会,然后发现应该是包含区间对存在有影响,就不知怎么做了...然后尚大神,说,So easy,你要倒着来,然后再正着来,判断是不是合法就行了.然后我乱写了写,就过了.数 ...
- cf D. Levko and Array
http://codeforces.com/contest/361/problem/D 用二分搜索相邻两个数的差的绝对值,然后用dp记录数改变的次数.dp[i]表示在i之前改变的次数,如果|a[i]- ...
- 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 ...
- CF360B Levko and Array (二分查找+DP)
链接:CF360B 题目: B. Levko and Array time limit per test 2 seconds memory limit per test 256 megabytes i ...
- Codeforces 361D Levko and Array(二分)(DP)
Levko and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- 有意思的DP(CF360B Levko and Array)
刚才面试了一个蛮有意思的DP题目,脑子断片,没写出来,不过早上状态还是蛮好的 一个长度为n的序列最多改变k次,使相邻两数之差绝对值的最大值最小 三维的dp我先尝试写一下 Codeforces 360B ...
- CodeForces - 361D Levko and Array
Discription Levko has an array that consists of integers: a1, a2, ... , an. But he doesn’t like this ...
- CF 1008C Reorder the Array
You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it ...
随机推荐
- 开启Apache mod_rewrite模块(解决404 Not Found)
网站搭建完成了,进入登录界面就是访问不了. 原因大概是没有开启Apache mod_rewrite模块,或者没有配置完全. 步骤1: 启用mod_rewrite模块 在conf目录的httpd.con ...
- 【转】android UI进阶之实现listview中checkbox的多选与记录--不错
原文网址:http://www.cnblogs.com/notice520/archive/2012/02/17/2355415.html 今天继续和大家分享涉及到listview的内容.在很多时候, ...
- JQuery 插件 - 弹窗:BlockUI
JQuery的弹窗插件,网上实在有很多做的比较好的,比如artDialog.layer,甚至EasyUI等等.这些在效果上做的非常好.但我觉得一个小小的弹窗提示,没有必要引用这些(其实是有点大材小用了 ...
- HDU 5506 - BestCoder Round #60 - GT and set
题目链接 : http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=641&pid=1003 题意 : 给N集 ...
- Dijkstra优先队列优化
Dijkstra算法的核心思想就是两步排序,一个是对于一个点而言,他的最小边要经过所有其他点最小边的测试才能确认,也就是说要在这其中找一个最大的边出来:第二个是对于每次循环而言的,每次的更新d数组都是 ...
- libvirtsAPI
mongodb远程服务器连接 mongo -uroot -p321 master.puppet.org:27017/admin
- 公告:本博客搬迁到:http://www.courtiercai.com/
公告: 您好,本人意见本博客搬迁到:http://www.courtiercai.com/.
- javascript 中的location.reload
location.reload()是什么意思 location.reload() 括号内有一个参数 true/false , 为空和false的效果一样. 如果该方法没有规定参数,或者参数是 fals ...
- ios NSString 去除空格和回车
去除两端空格 NSString *temp = [textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCh ...
- ExtJS4.2学习(11)——高级组件之Grid
大纲: 1.首先,搭建起来一个最基础的Grid组件: 2.其次,利用前边MVC架构将代码重构: 3.再者,介绍下Grid的一些特性. 一.搭建基础的Grid组件 在文章的开始,我们首先简单的搭建一个G ...