F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

xiaoxin and his watermelon candy

Time Limit: 4000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 535    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
1 5 1 2 3 4 5 3 1 3 1 4 1 5
 

Sample Output
1 2 3
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-26 03:49:15, Gzip enabled