Drazil and Park
题意翻译
有一只猴子,他生活在一个环形的公园里。有 $n$ 棵树围绕着公园。第$i$棵树和第$i+1$棵树之间的距离是 $d_i$ ,而第n棵树和第一棵树之间的距离是 $d_n$ 。第i棵树的高度是 $h_i$ 。
这只猴子每天要进行晨跑。晨跑的步骤如下:
· 他先选择两棵树;
· 然后爬上第一棵树;
· 再从第一棵树上下来,接着围绕着公园跑(有两个可能的方向)到第二棵树,然后爬上第二棵树;
· 最后从第二棵树上下来。
但是有一些小孩会在连续的一些树上玩耍。所以猴子不能经过这些树。
比如现在猴子选择的第$x$棵和第$y$棵树,那么该早晨他消耗的能量是 $2(hx+hy)+dist(x,y)$ 。由于某一条路径是被小孩子占据的,所以他只能跑另外一条,因此 $dist(x,y)$ 是确定的。
现在给出第i天,孩子们会在第 $a_i$ 棵树和 bi 棵树之间玩耍。具体的,如果 $ai≤bi$ ,那么孩子玩耍的区间就是 $[ai,bi]$ ,否则孩子玩耍的区间就是 $[ai,n]⋃[1,bi]$ 。
请帮助这只猴子找出两棵树,让他晨跑的时候他能够消耗最大的能量。
[Powered by Tony102](https://tony102.xyz/)
题目描述
Drazil is a monkey. He lives in a circular park. There are $ n $ trees around the park. The distance between the $ i $ -th tree and ( $ i+1 $ )-st trees is $ d_{i} $ , the distance between the $ n $ -th tree and the first tree is $ d_{n} $ . The height of the $ i $ -th tree is $ h_{i} $ .
Drazil starts each day with the morning run. The morning run consists of the following steps:
- Drazil chooses two different trees
- He starts with climbing up the first tree
- Then he climbs down the first tree, runs around the park (in one of two possible directions) to the second tree, and climbs on it
- Then he finally climbs down the second tree.
But there are always children playing around some consecutive trees. Drazil can't stand children, so he can't choose the trees close to children. He even can't stay close to those trees.
If the two trees Drazil chooses are $ x $ -th and $ y $ -th, we can estimate the energy the morning run takes to him as $ 2(h_{x}+h_{y})+dist(x,y) $ . Since there are children on exactly one of two arcs connecting $ x $ and $ y $ , the distance $ dist(x,y) $ between trees $ x $ and $ y $ is uniquely defined.
Now, you know that on the $ i $ -th day children play between $ a_{i} $ -th tree and $ b_{i} $ -th tree. More formally, if $ a_{i}<=b_{i} $ , children play around the trees with indices from range $ [a_{i},b_{i}] $ , otherwise they play around the trees with indices from ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF515E/d3b74f54842bc3f076dfae535193a349f2e5a3fa.png).
Please help Drazil to determine which two trees he should choose in order to consume the most energy (since he wants to become fit and cool-looking monkey) and report the resulting amount of energy for each day.
输入输出格式
输入格式
The first line contains two integer $ n $ and $ m $ ( $ 3<=n<=10^{5} $ , $ 1<=m<=10^{5} $ ), denoting number of trees and number of days, respectively.
The second line contains $ n $ integers $ d_{1},d_{2},...,d_{n} $ ( $ 1<=d_{i}<=10^{9} $ ), the distances between consecutive trees.
The third line contains $ n $ integers $ h_{1},h_{2},...,h_{n} $ ( $ 1<=h_{i}<=10^{9} $ ), the heights of trees.
Each of following $ m $ lines contains two integers $ a_{i} $ and $ b_{i} $ ( $ 1<=a_{i},b_{i}<=n $ ) describing each new day. There are always at least two different trees Drazil can choose that are not affected by children.
输出格式
For each day print the answer in a separate line.
输入输出样例
输入样例 #1
5 3
2 2 2 2 2
3 5 2 1 4
1 3
2 2
4 5
输出样例 #1
12
16
18
输入样例 #2
3 3
5 1 4
5 1 4
3 3
2 2
1 1
输出样例 #2
17
22
11