CodeForces 739C Alyona and towers
题目大意
给定一个长度为 n n的序列aa和 m m个操作,每个操作将[L,R][L,R]的元素加上 d d。
每次操作完后询问序列aa中最长的连续子序列满足 al<al+1<...<ax>...>ar−1>ar a_l...>a_{r-1}>a_r的长度是多少。
Data Constraint
n,m≤3×105 n,m\leq3\times10^5
题解
SRC
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std ;#define N 300000 + 10
typedef long long ll ;
struct Note {int Pre , Las , lans , rans , ans , len ;
} T[4*N] ;ll a[N] , b[N] ;
int n , m ;Note Merge( Note a , Note b ) {Note ret ;ret.len = a.len + b.len ;ret.Pre = a.Pre ;if ( a.Pre == a.len ) ret.Pre += b.Pre ;ret.Las = b.Las ;if ( b.Las == b.len ) ret.Las += a.Las ;ret.lans = a.lans ;if ( a.lans == a.len ) {if ( a.Las == a.len ) ret.lans += max( b.lans , b.Pre ) ;else ret.lans += b.Pre ;}ret.rans = b.rans ;if ( b.rans == b.len ) {if ( b.Pre == b.len ) ret.rans += max( a.rans , a.Las ) ;else ret.rans += a.Las ;}ret.ans = max( a.ans , b.ans ) ;ret.ans = max( ret.ans , max( ret.lans , ret.rans ) ) ;ret.ans = max( ret.ans , max( a.rans + ( a.Las ? max( b.lans , b.Pre ) : b.Pre ) , b.lans + ( b.Pre ? max( a.rans , a.Las ) : a.Las ) ) ) ;return ret ;
}void Update( int v ) {int ls = v + v , rs = v + v + 1 ;T[v] = Merge( T[ls] , T[rs] ) ;return ;
}void Build( int v , int l , int r ) {if ( l == r ) {if ( b[l] < 0 ) T[v].Pre = 1 ;else if ( b[l] > 0 ) T[v].Las = 1 ;if ( b[l] != 0 ) T[v].lans = T[v].rans = T[v].ans = 1 ;T[v].len = 1 ;return ;}int mid = (l + r) / 2 ;Build( v + v , l , mid ) ;Build( v + v + 1 , mid + 1 , r ) ;Update( v ) ;
}void Modify( int v , int l , int r , int x , int del ) {if ( l == x && r == x ) {b[x] += del ;T[v].Pre = T[v].Las = T[v].lans = T[v].rans = T[v].ans = 0 ;if ( b[l] < 0 ) T[v].Pre = 1 ;else if ( b[l] > 0 ) T[v].Las = 1 ;if ( b[l] != 0 ) T[v].lans = T[v].rans = T[v].ans = 1 ;return ;}int mid = (l + r) / 2 ;if ( x <= mid ) Modify( v + v , l , mid , x , del ) ;else Modify( v + v + 1 , mid + 1 , r , x , del ) ;Update( v ) ;
}int main() {scanf( "%d" , &n ) ;for (int i = 1 ; i <= n ; i ++ ) cin >> a[i] ;a[0] = a[1] ;for (int i = 1 ; i <= n ; i ++ ) b[i] = a[i] - a[i-1] ;Build( 1 , 1 , n ) ;scanf( "%d" , &m ) ;for (int i = 1 ; i <= m ; i ++ ) {int l , r , del ;scanf( "%d%d%d" , &l , &r , &del ) ;if ( l > 1 ) Modify( 1 , 1 , n , l , del ) ;if ( r < n ) Modify( 1 , 1 , n , r + 1 , -del ) ;printf( "%d\n" , T[1].ans + 1 ) ;}return 0 ;
}
CodeForces 739C Alyona and towers相关推荐
- Codeforces 739B Alyona and a tree (树上路径倍增及差分)
题目链接 Alyona and a tree 弄了好几个小时终于Accepted了,之后发现这个题是Div1的. 比较考验我思维的一道好题. 首先,做一遍DFS预处理出t[i][j]和d[i][j]. ...
- Codeforces Round #381 (Div. 2)
做不出题就来打一场模拟赛吧! http://codeforces.com/contest/740 A. Alyona and copybooks 水,直接暴力for吧,特判容易被HACK 1 #inc ...
- 有趣题目和认知合集(持续更新)
写写对一些算法的理解,挂几个有意思的题,可能也会挂几个板子题 算法理解偏向于能懂即可,没有严格的证明 快乐几何 [1.2]Volatile Kite 点到直线 快乐搜与暴力 [2.4]Short Co ...
- java 当前日期前一天_java获取当前日期的前一天和后一天
/** * 获得指定日期的前一天 * @param specifiedDay * @return * @throws Exception */ public static String getSpec ...
- Codeforces Round #358 (Div. 2) A. Alyona and Numbers 水题
A. Alyona and Numbers 题目连接: http://www.codeforces.com/contest/682/problem/A Description After finish ...
- Codeforces Round #381 (Div. 1) A. Alyona and mex 构造
传送门 文章目录 题意: 思路: 题意: 你需要确定一个长度为nnn的数组aaa,满足给定的mmm个[l,r][l,r][l,r]限制,需要保证构造出来的aaa数组对于每个[l,r][l,r][l,r ...
- Codeforces Round #401 (Div. 2) C Alyona and Spreadsheet —— 打表
题目链接:http://codeforces.com/contest/777/problem/C C. Alyona and Spreadsheet time limit per test 1 sec ...
- Educational Codeforces Round 98 (Rated for Div. 2) D. Radio Towers
Educational Codeforces Round 98 (Rated for Div. 2) D. Radio Towers 题目链接 There are n+2 towns located ...
- 【CodeForces - 777C】Alyona and Spreadsheet(思维,前缀和)
题干: During the lesson small girl Alyona works with one famous spreadsheet computer program and learn ...
最新文章
- 销售自己使用过的小汽车纳多少增值税
- 中石油训练赛 - Equidistant(bfs)
- 负载均衡工具 haproxy剖析
- python单元测试框架unittest介绍和使用_Python单元测试框架unittest简明使用实例
- 【转】牛人杰作 管饭哥登场
- 在使用刚体时的几个注意点和参数
- python编辑快速上手_Python编程如何快速上手,答案在这里
- 淘宝店铺店名起、分类如何定【太原网络营销师】教你
- pdf文件转换成jpg格式
- Chrome 安装插件与使用技巧
- 传奇3服务器配置文件,传奇3.0服务器的架设和设置详细介绍
- [渝粤教育] 西南科技大学 建筑CAD 在线考试复习资料
- 烧录flash_烧录固件完成后,配置JFLASH让程序自动运行
- 【苹果CMS技术教程】苹果CMSV10伪静态基础认识和设置教程
- 一次探索:基于香农熵预测DNA中编码序列,python实现。
- jQuery MiniUI 快速入门:Hollo, world!(二)_nikofan-ChinaUnix博客
- 【ceph】AsyncMessenger 网络模块总结--编辑中
- DSP看门狗实验源程序
- python绘制线型图
- 23种设计模式之桥接模式