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,r,m).求出区间[l,r]的最大值为m
现在告诉这么一些操作(<5000个),问能否找到一个原始的数列,有则输出YES与这个数列,否则输出NO,答案可能不唯一输出任何合法的都行。
题解:先给数组赋予最大的初值然后倒着处理,遇到1就减去。如果是2,将这一区间里所有数都去min(自身,MAX)
处理完之后然后正着来看一下是不是符合条件。由于数据比较小直接暴力也行。
#include <iostream>
#include <cstring>
#include <cstdio>
#define inf 0X3f3f3f3f
using namespace std;
typedef long long ll;
const int M = 5e3 + 10;
struct TnT {
int t , l , r , w;
}T[M];
ll a[M] , b[M];
int main() {
int n , m;
scanf("%d%d" , &n , &m);
for(int i = 0 ; i < m ; i++) {
scanf("%d%d%d%d" , &T[i].t , &T[i].l , &T[i].r , &T[i].w);
}
for(int i = 1 ; i <= n ; i++) {
a[i] = 25 * 100000000000;
}
int flag = 0;
for(int i = m - 1 ; i >= 0 ; i--) {
if(T[i].t == 1) {
for(int j = T[i].l ; j <= T[i].r ; j++) {
a[j] -= T[i].w;
}
}
else {
for(int j = T[i].l ; j <= T[i].r ; j++) {
a[j] = min(a[j] , (ll)T[i].w);
}
}
}
for(int i = 1 ; i <= n ; i++) {
b[i] = a[i];
}
for(int i = 0 ; i < m ; i++) {
if(T[i].t == 1) {
for(int j = T[i].l ; j <= T[i].r ; j++) {
b[j] += T[i].w;
}
}
else {
int count = 0;
for(int j = T[i].l ; j <= T[i].r ; j++) {
if(b[j] > T[i].w) {
flag = 1;
break;
}
if(b[j] == T[i].w) count++;
}
if(!count) {
flag = 1;
break;
}
}
if(flag) break;
}
if(flag) printf("NO\n");
else {
printf("YES\n");
for(int i = 1 ; i <= n ; i++) {
a[i] = min((ll)1000000000 , a[i]);
a[i] = max((ll)-1000000000 , a[i]);
printf("%I64d " , a[i]);
}
printf("\n");
}
return 0;
}
codeforces 361 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 361 D. Levko and Array(dp+二分)
题目链接:http://codeforces.com/contest/361/problem/D 题意:最多可以修改K次数字,每次修改一个数字变成任意值,C=max(a[i+1]-a[i]):求操作之 ...
- Codeforces Round #210 (Div. 2) C. Levko and Array Recovery
题目链接 线段树的逆过程,想了老一会,然后发现应该是包含区间对存在有影响,就不知怎么做了...然后尚大神,说,So easy,你要倒着来,然后再正着来,判断是不是合法就行了.然后我乱写了写,就过了.数 ...
- cf C. Levko and Array Recovery
http://codeforces.com/contest/361/problem/C 这道题倒着一次,然后正着一次,在正着的一次的时候判断合不合法就可以. #include <cstdio&g ...
- codeforces 465 C. No to Palindromes!(暴力+思维)
题目链接:http://codeforces.com/contest/465/problem/C 题意:给出一个不存在2个或以上回文子串的字符串,全是由小写字母组成而且字母下表小于p,问刚好比这个字符 ...
- 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 ...
- CF360B Levko and Array (二分查找+DP)
链接:CF360B 题目: B. Levko and Array time limit per test 2 seconds memory limit per test 256 megabytes i ...
- [Codeforces 266E]More Queries to Array...(线段树+二项式定理)
[Codeforces 266E]More Queries to Array...(线段树+二项式定理) 题面 维护一个长度为\(n\)的序列\(a\),\(m\)个操作 区间赋值为\(x\) 查询\ ...
随机推荐
- 百度网盘 人工智能书籍【Tensorflow和深度学习】
链接:https://pan.baidu.com/s/1ejCvwn08ILI2fMhBEdXR8w 提取码:6pk9
- SmartSql使用教程(4)——多库配置与使用
一.引言 已经几个月没更新了.本来上一章的预告是准备写TypeHandler的相关特性的.但是在准备的时候.SmartSql的作者重构了一下TypeHandler,使得我一下子没搞懂TypeHandl ...
- Windbg程序调试系列-索引篇
最近整理了一下Windbg程序调试系列的文章,做个了索引贴,方便大家查询.搜索: Windbg程序调试系列1-常用命令说明&示例 Windbg程序调试系列1-Mex扩展使用总结 Windbg程 ...
- asp.net core系列 69 Amazon S3 资源文件上传示例
一. 上传示例 Install-Package AWSSDK.S3 -Version 3.3.104.10 using Amazon; using Amazon.Runtime; using Ama ...
- 一文读懂tomcat组件--一个web服务器的架构演化史
1. tomcat是谁? 2. tomcat可以做什么? tomcat是一个web容器,可以将web应用部署到tomcat,由它提供web服务,一个web容器中可以部署多个web应用,这些we ...
- 使用python画2D线条
"""用于验证整体趋势正确性,不做关闭操作时保持显示""" #!python3 #-*- coding:utf-8 -*- import m ...
- java高并发系列 - 第25天:掌握JUC中的阻塞队列
这是java高并发系列第25篇文章. 环境:jdk1.8. 本文内容 掌握Queue.BlockingQueue接口中常用的方法 介绍6中阻塞队列,及相关场景示例 重点掌握4种常用的阻塞队列 Queu ...
- Python 命令行之旅 —— 深入 argparse (一)
作者:HelloGitHub-Prodesire HelloGitHub 的<讲解开源项目>系列,项目地址:https://github.com/HelloGitHub-Team/Arti ...
- Json对象转Ts类
一 目标 推荐一款在线将Json对象转换为Ts类的工具:https://apihelper.jccore.cn/jsontool 可以帮助前端开发人员提高开发效率. 二 背景 Json是一种轻量级的数 ...
- 【redis】redis基础命令学习集合
写在前面 Redis是一个高速的内存数据库,它的应用十分广泛,可以说是服务端必学必精的东西.然而,学以致用,无用则无为.学了的东西必须反复的去用,去实践,方能有真知.这篇文章记录了我在redis学习过 ...