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[ ...
随机推荐
- C++并发编程 异步任务
C++并发编程 异步任务 异步任务 std::async (1) std::async 会返回一个 std::future 对象, 这个对象持有最终计算出来的结果. 当需要这个值时, 只需要调用对象的 ...
- 转--snmp如何被tr069替代
Form:本期话题:技术点详解---新型网管理念TR-069 一. 带内网管与带外网管 网络设备是一种资产,资产往往都需要进行管理,网络设备也不例外,网络设备的作用是网络互联,网络应用是一种实时交互性 ...
- linux命令行设置git提示符
http://note.youdao.com/noteshare?id=3b6b2ee0925964928fd63d2c51e6bcef
- 手脱Upack 2.x - 3.x
1.PEID查壳 Upack 2.x - 3.x Heuristic Mode -> Dwing 2.载入OD,一上来就是一个大跳转,先F8跟一会 >- E9 56D40300 jmp 跑 ...
- centos7.2的yum安装mysql和修改初始密码
一.centos7.2安装mysql CentOS 7之后的版本yum的默认源中使用MariaDB替代原先MySQL,因此安装方式较为以往有一些改变: 下载mysql的源 wget http://de ...
- java-压缩文件成zip文件(多文件/单文件/多目录/单目录/无目录),用于下载
本博客是自己在学习和工作途中的积累与总结,仅供自己参考,也欢迎大家转载,转载时请注明出处. http://www.cnblogs.com/king-xg/p/6424788.html 上代码: pac ...
- svnserver配置详解
svnserve是SVN自带的一个轻型服务器,客户端通过使用以svn://或svn+ssh://为前缀的URL来访问svnserve服务器,实现远程访问SVN版本库. svnserve可以通过配置文件 ...
- 倍增求lca模板
倍增求lca模板 https://www.luogu.org/problem/show?pid=3379 #include<cstdio> #include<iostream> ...
- .net core 中 identity server 4 之Topic --定义Client
客户端指能够从id4获取Token的角色. 客户端的共性: a unique client ID a secret if needed the allowed interactions with th ...
- 【转】ubuntu 11.04使用apt-get安装软件时一直提示E:unable to locate package
问题: VMware虚拟机安装了ubuntu 11.04,在使用apt-get安装软件时一直提示E:Unable to locate package. 百度了原因,说是要更新源,使用命令:sudo a ...