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的更多相关文章

  1. 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. ...

  2. 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 ...

  3. Codeforces Round #292 (Div. 2) C. Drazil and Factorial

    题目链接:http://codeforces.com/contest/515/problem/C 给出一个公式例如:F(135) = 1! * 3! * 5!; 现在给你一个有n位的数字a,让你求这样 ...

  4. Codeforces Round #292 (Div. 1) B. Drazil and Tiles (类似拓扑)

    题目链接:http://codeforces.com/problemset/problem/516/B 一个n*m的方格,'*'不能填.给你很多个1*2的尖括号,问你是否能用唯一填法填满方格. 类似t ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. Codeforces Round #292 (Div. 1)A. Drazil and Factorial 构造

    A. Drazil and Factorial 题目连接: http://codeforces.com/contest/516/problem/A Description Drazil is play ...

  9. codeforces 516c// Drazil and Park// Codeforces Round #292(Div. 1)

    题意:一个圆环上有树,猴子上下其中一棵树,再沿着换跑,再上下另一棵树.给出一个区间,问最大的运动距离是. 给出区间大小dst,和数高数组arr. 设区间[x,y],a[x]=2*arr[x]+dst[ ...

随机推荐

  1. 二叉树系列 - 二叉树的深度,例 [LeetCode]

    二叉树的深度的概念最值得注意的地方,在于 到"叶子"节点的距离. 一般来说,如果直接说“深度”,都是指最大深度,即最远叶子的距离. 这里放两道例题,最小深度和最大深度. 1. 二叉 ...

  2. Hadoop 遇到的问题集

    1. Mac 使用ssh命令无法成功 ssh localhost,但是可以ssh其他的 可能原因:ssh服务未启动 解决方法: 1.启动sshd服务: sudo launchctl load -w / ...

  3. Linux 目录详解 树状目录结构图

    1.树状目录结构图 2./目录 目录 描述 / 第一层次结构的根.整个文件系统层次结构的根目录. /bin/ 需要在单用户模式可用的必要命令(可执行文件):面向所有用户,例如:cat.ls.cp,和/ ...

  4. Centos 7 下搭建 Dokuwiki

    Centos 7 下搭建 Dokuwiki # Dokuwiki 是php的,所以要先搭建php环境,下载 apache和php,第1.2步下载完,相关的依赖都会下载## 1.下载 httpdyum ...

  5. MagicB.0—怎样设置电脑自动关机?

    天太晚了,该睡觉了,可是你的东西也许正在下载,软件正在更新,总之电脑还有一些工作没有完成,又不需要你人为的守着,随他去吧!可是电脑已经工作了一天了,它也要休息一下,再者也不能浪费电力资源呀,那么就来使 ...

  6. 小程序 mcrypt加密拓展在php7.1 废弃 使用openssl替代方案

    原加密方法 使用mcrypt //获得16位随机字符串,填充到明文之前 $random = $this->getRandomStr(); $text = $random . pack(" ...

  7. yii2 自动登录解读

    今日遇到一个需要将当前用户,全部登出系统(YII2框架制作)重新登录的需求 仔细回忆一遍,Yii2的登录流程,竟然有些不太明白,于是下午空闲时 重新看了下Yii2的用户登录源码 文件位于YII2项目下 ...

  8. escapeRegExp捕捉通配符的代码解析

    费了好几个小时,把一小段正则代码搞通了,回顾并记下,加深记忆. 该段代码来自yii.js,它也是引自stackoverflow,地址是:http://stackoverflow.com/questio ...

  9. pycharm双击无响应,打不开问题解决办法

    之前好好的pycharm,突然双击打不开了,怎么办? 亲测有效方案: 第一步:进入如下路径,找到cmd.exe,右键选择“以管理员身份运行”: 第二步:在打开的cmd窗口中,输入 netsh wins ...

  10. $FFT$(快速傅里叶变换)

    - 概念引入 - 点值表示 对于一个$n - 1$次多项式$A(x)$,可以通过确定$n$个点与值(即$x$和$y$)来表示这唯一的$A(x)$ - 复数 对于一元二次方程 $$x^2 + 1 = 0 ...