当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5654:xiaoxin and his watermelon candy

题目描述
During his six grade summer vacation, xiaoxin got lots of watermelon candies from his leader when he did his internship at Tencent. Each watermelon candy has it's sweetness which denoted by an integer number.

xiaoxin is very smart since he was a child. He arrange these candies in a line and at each time before eating candies, he selects three continuous watermelon candies from a specific range [L, R] to eat and the chosen triplet must satisfies:

if he chooses a triplet $(a_i, a_j, a_k)$ then:
1. $j = i + 1, k = j + 1$
2.  $a_i \leq a_j \leq a_k$

Your task is to calculate how many different ways xiaoxin can choose a triplet in range [L, R]?
two triplets $(a_0, a_1, a_2)$ and $(b_0, b_1, b_2)$ are thought as different if and only if:
$a_0 \neq b_0$ or $a_1 \neq b_1$ or $a_2 \neq b_2$
输入解释
This problem has multi test cases. First line contains a single integer $T(T\leq 10)$ which represents the number of test cases.

For each test case, the first line contains a single integer $n(1 \leq n \leq 200,000)$which represents number of watermelon candies and the following line contains $n$ integer numbers which are given in the order same with xiaoxin arranged them from left to right.
The third line is an integer $Q(1 \leq 200,000)$ which is the number of queries. In the following $Q$ lines, each line contains two space seperated integers $l, r(1\leq l \leq r \leq n)$ which represents the range [l, r].
输出解释
For each query, print an integer which represents the number of ways xiaoxin can choose a triplet.
输入样例
1
5
1 2 3 4 5
3
1 3
1 4
1 5
输出样例
1
2
3
来自杭电HDUOJ的附加信息
Recommend wange2014

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-5654

最后修改于 2020-10-25T23:24:33+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
4000/4000MS(Java/Others) 65536/65536K(Java/Others)