Codeforces Round #292 (Div. 1) C - Drazil and Park
每个点有两个值Li 和 Bi,求Li + Rj (i < j) 的最大值,这个可以用线段树巧妙的维护。。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PII pair<int, int>
#define y1 skldjfskldjg
#define y2 skldfjsklejg using namespace std; const int N = 2e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ; int n, m;
LL d[N], h[N], sum[N]; struct node {
LL mx1, mx2, mx3;
node operator + (const node &rhs) const {
node ans;
ans.mx1 = max(mx1, rhs.mx1);
ans.mx2 = max(mx2, rhs.mx2);
ans.mx3 = max(mx3, rhs.mx3);
ans.mx3 = max(ans.mx3, mx1 + rhs.mx2);
return ans;
}
} a[N << ]; void build(int l, int r, int rt) {
if(l == r) {
a[rt].mx1 = * h[l] - sum[l - ];
a[rt].mx2 = * h[l] + sum[l - ];
a[rt].mx3 = -INF;
return;
}
int mid = l + r >> ;
build(l, mid, rt << );
build(mid + , r, rt << | );
a[rt] = a[rt << ] + a[rt << | ];
} node query(int L, int R, int l, int r, int rt) {
if(l >= L && r <= R) return a[rt];
int mid = l + r >> ;
if(R <= mid) return query(L, R, l, mid, rt << );
if(L > mid) return query(L, R, mid + , r, rt << | );
return query(L, R, l, mid, rt << ) + query(L, R, mid + , r, rt << | );
} int main() {
scanf("%d%d", &n, &m);
for(int i = ; i <= n; i++) scanf("%lld", &d[i]), d[i + n] = d[i];
for(int i = ; i <= n; i++) scanf("%lld", &h[i]), h[i + n] = h[i];
for(int i = ; i <= * n; i++) sum[i] = sum[i - ] + d[i];
build(, * n, ); while(m--) {
int L, R; scanf("%d%d", &L, &R);
L--, R--;
L = (L - + n) % n;
R = (R + ) % n;
L++, R++;
swap(L, R);
if(L > R) R += n;
printf("%lld\n", query(L, R, , * n, ).mx3);
}
return ;
} /*
*/
Codeforces Round #292 (Div. 1) C - Drazil and Park的更多相关文章
- Codeforces Round #292 (Div. 1) C. Drazil and Park 线段树
		
C. Drazil and Park 题目连接: http://codeforces.com/contest/516/problem/C Description Drazil is a monkey. ...
 - Codeforces Round #292 (Div. 1) B. Drazil and Tiles 拓扑排序
		
B. Drazil and Tiles 题目连接: http://codeforces.com/contest/516/problem/B Description Drazil created a f ...
 - Codeforces Round #292 (Div. 2) C. Drazil and Factorial
		
题目链接:http://codeforces.com/contest/515/problem/C 给出一个公式例如:F(135) = 1! * 3! * 5!; 现在给你一个有n位的数字a,让你求这样 ...
 - Codeforces Round #292 (Div. 1) B. Drazil and Tiles (类似拓扑)
		
题目链接:http://codeforces.com/problemset/problem/516/B 一个n*m的方格,'*'不能填.给你很多个1*2的尖括号,问你是否能用唯一填法填满方格. 类似t ...
 - Codeforces Round #292 (Div. 1) - B. Drazil and Tiles
		
B. Drazil and Tiles Drazil created a following problem about putting 1 × 2 tiles into an n × m gri ...
 - Codeforces Round #292 (Div. 2) D. Drazil and Tiles [拓扑排序 dfs]
		
传送门 D. Drazil and Tiles time limit per test 2 seconds memory limit per test 256 megabytes Drazil cre ...
 - Codeforces Round #292 (Div. 2) C. Drazil and Factorial 515C
		
C. Drazil and Factorial time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
 - Codeforces Round #292 (Div. 1)A. Drazil and Factorial 构造
		
A. Drazil and Factorial 题目连接: http://codeforces.com/contest/516/problem/A Description Drazil is play ...
 - codeforces 516c// Drazil and Park// Codeforces Round #292(Div. 1)
		
题意:一个圆环上有树,猴子上下其中一棵树,再沿着换跑,再上下另一棵树.给出一个区间,问最大的运动距离是. 给出区间大小dst,和数高数组arr. 设区间[x,y],a[x]=2*arr[x]+dst[ ...
 
随机推荐
- 前端PHP入门-023-重点日期函数之程序执行时间检测
			
我们有的时经常需要做程序的执行时间执行效率判断. 实现的思路如下: <?php //记录开始时间 //记录结整时 // 开始时间 减去(-) 结束时间 得到程序的运行时间 ?> 可是大家不 ...
 - 动态规划:双重DP
			
之前做过的传纸条那道题就是双重动态规划的典型应用,题意就不描述了,直接贴一下以前写过的,经典代码 #include<iostream> using namespace std; ,maxm ...
 - css3中新增的样式使用方法
			
在PC版开发中由于IE原因,我们很少用到css3,但随着平板和智能手机进入我们的生活,以及现在越来越流行,在手机版和平板版开发中我们就可以大胆的使用了,下面我们探讨常用几个css3属性: 1.css3 ...
 - Web 开发人员需知的 Web 缓存知识
			
今天踩着前辈们的肩膀,再次把这篇文章翻译整理下.一来让自己对web缓存的理解更深刻些,二来让大家注意力稍稍转移下,不要整天HTML5, 面试题啊叨啊叨的~~ 什么是Web缓存,为什么要使用它? Web ...
 - 铺地砖|状压DP练习
			
有一个N*M(N<=5,M<=1000)的棋盘,现在有1*2及2*1的小木块无数个,要盖满整个棋盘,有多少种方式?答案只需要mod1,000,000,007即可. //我也不知道这道题的来 ...
 - 根据 plist 还原 图片
			
1. python 环境自己配置(支持windows Mac ) 2. 把所有的 plist 和 大图片放到一个目录下 3.如果添加了 系统环境变量 就直接双击运行脚本,如果没有设置,把脚本拽到DO ...
 - C - Contest Setting Gym - 101982C   dp 补题
			
题目链接:https://vjudge.net/contest/273260#problem/C 学习了一下别人的思路,首先去重,然后离散化. dp数组开二维,每一次更新,状态转移方程,dp[ i ] ...
 - Sqlmap注入技巧收集整理
			
TIP1 当我们注射的时候,判断注入 http://site/script?id=10http://site/script?id=11-1 # 相当于 id=10http://site/script? ...
 - 简单实现JS上传图片预览功能
			
HTML代码 <div class="upload"> <input type="button" class="btn" ...
 - 前端内容转译html
			
其他地方采集过来的可以转译下,试试这个:var returnReg = /\n/g; detail = detail.replace(returnReg,""); var reg ...