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

First One

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 5013    Accepted Submission(s): 1297


Problem Description
soda has an integer array $a_1, a_2, \dots, a_n$. Let $S(i,j)$ be the sum of $a_i, a_{i+1}, \dots, a_j$. Now soda wants to know the value below: $$\sum_{i=1}^{n} \sum_{j=i}^{n} (\lfloor \log_2 S(i,j) \rfloor + 1) \times (i + j)$$
Note: In this problem, you can consider $\log_2 0$ as 0.
 

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 line contains an integer $n$ $(1 \le n \le 10^5)$, the number of integers in the array.
The next line contains $n$ integers $a_1, a_2, \dots, a_n$ $(0 \le a_i \le 10^5)$.
 

Output
For each test case, output the value.
 

Sample Input
1 2 1 1
 

Sample Output
12
 

Author
zimpha@zju
 

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-19 19:36:22, Gzip enabled