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 ...
随机推荐
- Leetcode:Largest Number详细题解
题目 Given a list of non negative integers, arrange them such that they form the largest number. For e ...
- COJ 0995 WZJ的数据结构(负五)区间操作
WZJ的数据结构(负五) 难度级别:C: 运行时间限制:1000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 请你设计一个数据结构,完成以下功能: 给定一个大小为 ...
- Codeforces Round #236 (Div. 2)E. Strictly Positive Matrix(402E)
E. Strictly Positive Matrix You have matrix a of size n × n. Let's number the rows of the matrix f ...
- 从一个聊天信息引发的思考之Android事件分发机制
转载请声明:http://www.cnblogs.com/courtier/p/4295235.html 起源: 我在某一天看到了下面的一条信息(如下图),我想了下(当然不是这 ...
- jquery 滚动条 scroll 和 animate出现的问题总结
这两天刚刚学习了jquery就想把平时做看到的一些相关效果用新的知识写写看.知识平时看着都懂,实际操作中问题才会层出不穷. <!DOCTYPE html> <html> < ...
- Android学习之路——Android四大组件之activity(二)数据的传递
上一篇讲了activity的创建和启动,这一篇,我们来讲讲activity的数据传递 activity之间的数据传递,这里主要介绍的是activity之间简单数据的传递,直接用bundle传递基本数据 ...
- 自定义控件(视图)2期笔记03:自定义控件之使用系统控件(优酷案例之广告条Viewpager)
1.首先我们看看运行效果,如下: 2. 下面就是详细实现这个效果的过程: (1)新建一个Android工程,命名为"广告条的效果",如下: (2)这里用到一个控件ViewPager ...
- USB设备架构
USB设备,分为3层:1.底层为传送和接受数据的总线接口:2.中间层处理总线和不同端点的数据传输:3.最高层由串行总线设备提供.主要研究中间层. USB设备状态,主要研究外部可见状态. 1,连接态-- ...
- 2:numpy---ndarray
ndarray即是多维数组[n dimension array] 一:创建ndarray 有好几种创建数组的方法. 例如,你可以使用 array 函数从常规的Python列表和元组创造数组.所创建的数 ...
- linux局域网不能相互访问
1.关闭防火墙 /etc/init.d/iptable stop 2.关闭selinux 1.临时禁用SELinux: root@server# setenforce 0 这样重启服务器之后 ...