|
||||||||||
xiaoxin and his watermelon candyTime Limit: 4000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 543 Accepted Submission(s): 153 Problem Description 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$ Input 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]. Output For each query, print an integer which represents the number of ways xiaoxin can choose a triplet. Sample Input
Sample Output
Source | ||||||||||
|