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

Eades

Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 352    Accepted Submission(s): 181


Problem Description
Peter has a number sequence $a_1, a_2, ..., a_n$. Let $g(l,r)$ be the maximum value of the subsequence $a_{l},a_{l+1},...,a_{r}$ and $f(l,r)=\displaystyle\sum_{i=l}^{r}[a_i = g(l,r)]$. Note that $[\text{condition}] = 1$ if $\text{condition}$ is true, or $0$ otherwise.

Peter wants to know the number of integer pairs $l$ and $r$ $(l \le r)$ such that $f(l,r)=k$, for every integer $k \in \{1, 2, ..., n\}$.
 

Input
There are multiple test cases. The first line of input contains an integer $T$ indicating the number of test cases. For each test case:

The first contains an integer $n$ $(1 \le n \le 60000)$ -- the length of the sequence. The second line contains $n$ integers $a_1,a_2,...,a_n$ $(1 \le a_i \le n)$.
 

Output
For each test case, output an integer $S = \displaystyle\sum_{k=1}^{n}k \oplus z_k$, where $z_k$ is the number of integer pairs $l$ and $r$ $(l \le r)$ that $f(l,r)=k$ and $\oplus$ denotes the bitwise exclusive or operation.
 

Sample Input
3 3 1 2 3 4 1 1 1 1 6 1 2 2 1 1 2
 

Sample Output
12 12 36
 

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-11-22 18:16:28, Gzip enabled