Codeforces Round #210 (Div. 2) C. Levko and Array Recovery
线段树的逆过程,想了老一会,然后发现应该是包含区间对存在有影响,就不知怎么做了。。。然后尚大神,说,So easy,你要倒着来,然后再正着来,判断是不是合法就行了。然后我乱写了写,就过了。数据难道又水了。。。
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
int p[],o[],ans[];
int t[],l[],r[],d[];
int main()
{
int n,m,i,j,flag,maxz;
scanf("%d%d",&n,&m);
for(i = ;i <= n;i ++)
p[i] = -;
for(i = ;i <= m;i ++)
{
scanf("%d%d%d%d",&t[i],&l[i],&r[i],&d[i]);
}
flag = ;
for(i = m;i >= ;i --)
{
if(t[i] == )
{
for(j = l[i];j <= r[i];j ++)
p[j] -= d[i];
}
else
{
for(j = l[i];j <= r[i];j ++)
{
if(o[j]&&p[j] < d[i]) continue;
p[j] = d[i];
o[j] = ;
}
}
}
for(i = ;i <= n;i ++)
ans[i] = p[i];
for(i = ;i <= m;i ++)
{
if(t[i] == )
{
for(j = l[i];j <= r[i];j ++)
p[j] += d[i];
}
else
{
maxz = -;
for(j = l[i];j <= r[i];j ++)
{
maxz = max(maxz,p[j]);
}
if(maxz != d[i]) flag = ;
}
}
if(flag)
printf("NO\n");
else
{
printf("YES\n");
for(i = ;i <= n;i ++)
{
if(i == )
printf("%d",ans[i]);
else
printf(" %d",ans[i]);
}
printf("\n");
}
return ;
}
Codeforces Round #210 (Div. 2) C. Levko and Array Recovery的更多相关文章
- Codeforces Round #210 (Div. 2) A. Levko and Table
让对角线的元素为k就行 #include <iostream> using namespace std; int main() { int n,k; cin >> n > ...
- CodeForces 360E Levko and Game(Codeforces Round #210 (Div. 1))
题意:有一些无向边m条权值是给定的k条权值在[l,r]区间可以由你来定,一个点s1 出发一个从s2出发 问s1 出发的能不能先打到f 思路:最短路. 首先检测能不能赢 在更新的时候 如果对于一条边 ...
- Codeforces Round #210 (Div. 1).B
经典的一道DP题. 题目明显是一道DP题,但是比赛的时候一个劲就在想怎么记录状态和转移.最后想到了一种n^3的方法,写了下,不出所料的超时了. 看了别人的代码才发现竟然是先二分然后再进行DP,像这种思 ...
- Codeforces Round #179 (Div. 1) A. Greg and Array 离线区间修改
A. Greg and Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/295/pro ...
- Codeforces Round #331 (Div. 2) B. Wilbur and Array 水题
B. Wilbur and Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596/p ...
- Codeforces Round #258 (Div. 2) B. Sort the Array
题目链接:http://codeforces.com/contest/451/problem/B 思路:首先找下降段的个数,假设下降段是大于等于2的,那么就直接输出no,假设下降段的个数为1,那么就把 ...
- Codeforces Round #510 (Div. 2) D. Petya and Array(离散化+反向树状数组)
http://codeforces.com/contest/1042/problem/D 题意 给一个数组n个元素,求有多少个连续的子序列的和<t (1<=n<=200000,abs ...
- Codeforces Round #374 (Div. 2) D. Maxim and Array 贪心
D. Maxim and Array 题目连接: http://codeforces.com/contest/721/problem/D Description Recently Maxim has ...
- Codeforces Round #373 (Div. 2) E. Sasha and Array 线段树维护矩阵
E. Sasha and Array 题目连接: http://codeforces.com/contest/719/problem/E Description Sasha has an array ...
随机推荐
- probe函数何时调用的
转自:http://blog.csdn.net/xiafeng1113/article/details/8030248 Linux中 probe函数何时调用的 所以的驱动教程上都说:只有设备和驱动的名 ...
- .NET生成带Logo的二维码
使用ThoughtWorks.QRCode生成,利用这个库来生成带Logo的二维码(就是中间嵌了一个图片的二维码),直接见代码: HttpContext context = HttpContext.C ...
- jQuery Mobile学习之grid、等待显示的ajax效果、页面跳转、页面跳转传递参数等(二)
Index.cshtml <!-- Start of second page --> <section data-role="page" id="bar ...
- Delphi的Win32的API调用简单介绍
1. 介绍Win32 API和Win32系统.还要讨论Win32系统的功能以及它与16位系统在功能上的几个主要区别.只是让对Win32系统有一个基本的了解.当已经基本了解Win32操作后,就可 ...
- 游戏主循环(Game Loop)
游戏主循环是游戏的心跳,一般使用while循环进行主动刷新. 一次循环由获取用户输入.更新游戏状态.处理AI.播放音乐和绘制画面组成. 这些行为可以分成两类: update_game(); // 更新 ...
- Java 初学记录之一 快速输入
1. sysout 按回车 System.out.println();
- 向Word模板中填充数据
现在有这样的需求,给Word文档的指定位置填充上特定数据,例如我们有一个终端,用来打印员工的薪资证明,对于一个公司来说,他的薪资证明模板是固定的,变化的地方是员工姓名,部门,职位等.我们只需要将这些指 ...
- uint8_t / uint16_t / uint32_t /uint64_t 是什么数据类型 - 大总结,看完全明白了
转自:http://blog.csdn.net/kiddy19850221/article/details/6655066 uint8_t / uint16_t / uint32_t /uint64_ ...
- Centos7-mqtt消息中间件mosquitto的安装和配置
在以前发布的博客"菜鸟是如何打造智能家居系统的"文章最后我提到了使用MQTT协议作为云平台和设备之间的通信协议以达到消息传递的实时性,手机的消息推送也大多基于这种平台,首先搬来一段 ...
- 视觉差双排listview效果
https://github.com/bavariama1/ListBuddies