Upload code_segments/segment_138.txt with huggingface_hub
Browse files
code_segments/segment_138.txt
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
We define the $\operatorname{MAD}$ (Maximum Appearing Duplicate) in an array as the largest number that appears at least twice in the array. Specifically, if there is no number that appears at least twice, the $\operatorname{MAD}$ value is $0$.
|
| 2 |
+
|
| 3 |
+
For example, $\operatorname{MAD}([1, 2, 1]) = 1$, $\operatorname{MAD}([2, 2, 3, 3]) = 3$, $\operatorname{MAD}([1, 2, 3, 4]) = 0$.
|
| 4 |
+
|
| 5 |
+
You are given an array $a$ of size $n$. Initially, a variable $sum$ is set to $0$.
|
| 6 |
+
|
| 7 |
+
The following process will be executed in a sequential loop until all numbers in $a$ become $0$:
|
| 8 |
+
|
| 9 |
+
1. Set $sum := sum + \sum_{i=1}^{n} a_i$; 2. Let $b$ be an array of size $n$. Set $b_i :=\ \operatorname{MAD}([a_1, a_2, \ldots, a_i])$ for all $1 \le i \le n$, and then set $a_i := b_i$ for all $1 \le i \le n$.
|
| 10 |
+
|
| 11 |
+
Find the value of $sum$ after the process.
|
| 12 |
+
|
| 13 |
+
The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) — the number of test cases.
|
| 14 |
+
|
| 15 |
+
For each test case:
|
| 16 |
+
|
| 17 |
+
* The first line contains an integer $n$ ($1 \leq n \leq 2 \cdot 10^5$) — the size of the array $a$; * The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq n$) — the elements of the array.
|
| 18 |
+
|
| 19 |
+
It is guaranteed that the sum of $n$ over all test cases will not exceed $2 \cdot 10^5$.
|
| 20 |
+
|
| 21 |
+
For each test case, output the value of $sum$ in a new line.
|
| 22 |
+
|
| 23 |
+
In the first test case, $a=[1]$ initially.
|
| 24 |
+
|
| 25 |
+
In the first loop:
|
| 26 |
+
|
| 27 |
+
1. Set $sum := sum + a_1 = 0+1=1$; 2. Set $b_1 :=\ \operatorname{MAD}([a_1])=\ \operatorname{MAD}([1])=0$, and then set $a_1 := b_1$.
|
| 28 |
+
|
| 29 |
+
After the first loop, $a=[0]$ and the process ends. The value of $sum$ after the process is $1$.
|
| 30 |
+
|
| 31 |
+
In the second test case, $a=[2,2,3]$ initially.
|
| 32 |
+
|
| 33 |
+
After the first loop, $a=[0,2,2]$ and $sum=7$.
|
| 34 |
+
|
| 35 |
+
After the second loop, $a=[0,0,2]$ and $sum=11$.
|
| 36 |
+
|
| 37 |
+
After the third loop, $a=[0,0,0]$ and $sum=13$. Then the process ends.
|
| 38 |
+
|
| 39 |
+
The value of $sum$ after the process is $13$.
|