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 ...
随机推荐
- YII增加全局函数
法1: 在使用Yii开发中我们经常会遇到一个问题,每次使用Yii的组件.扩展等,我们会像下面一样去写: <?php Yii::app()->user; Yii::app()->get ...
- asp.net 1.1网站开发配置出现”Visual Studio .NET 无法创建或打开应用程序”解决方法
可能的解决方案: 1.注册.net framework 1.1 C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_regiis /i 2,如果配置 ...
- [React] React Router: Named Components
In this lesson we'll learn how to render multiple component children from a single route. Define a n ...
- wpf 中自定义控件及其使用
主要有3个步骤: 1. 首先创建一个自定义的控件,该控件继承 TextBox namespace EzIntePark.Presentation.Common { /// <summary> ...
- Java基础知识强化34:String类之String类的转换功能
1. String类的转换功能 String[] split(String regex)//将字符串变成字符串数组(字符串切割) byte[] getBytes()//将字符串变成字节数组 char[ ...
- firefox 不能显示 glyphicons 字体
折腾了很久才发现是firefox 不能跨域下载相应的字体文件,将bootstrap相应的css文件和字体文件copy到调用的项目里,问题才得以解决.
- visual studio插件 visual assistx
http://www.wholetomato.com/downloads/CheckForUpdate.asp?v=1925&e=&b=n&r=y&i=10&v ...
- 关于javascript中setTimeout()和clearTimeout()的疑惑。
由于在w3school中学习javascript时,当学到setTimeout()和clearTimeout()方法时.根据它所提供的例子(下面的代码转自w3cschool)—计数程序,发现当你不停的 ...
- poj3685 二分套二分
F - 二分二分 Crawling in process... Crawling failed Time Limit:6000MS Memory Limit:65536KB 64bit ...
- 神经网络作业: NN LEARNING Coursera Machine Learning(Andrew Ng) WEEK 5
在WEEK 5中,作业要求完成通过神经网络(NN)实现多分类的逻辑回归(MULTI-CLASS LOGISTIC REGRESSION)的监督学习(SUOERVISED LEARNING)来识别阿拉伯 ...