Beauty of Array Time limit: 2 Seconds Memory Limit: 65536 KB
Edward has a array A with N integers. He defines the beauty of an array as the summation of a distinct integers in the array. Now Edward wants to know the summation of the beauty of all contiguous subarray of the array A .
Input
There is multiple test cases. The first line of input contains an integer indicating the number of the T test cases. For each test case:
The first line contains an integer N (1 <= N <= 100000), which indicates the size of the array. The next line contains N positive integers separated by spaces. Every integer is no larger than 1000000.
Output
For each case, print the answer on one line.
Sample Input
351 2 3 4 532 3 342 3 3 2
Sample Output
1052138 Test Instructions: self-translation. What I was thinking was the tree-like numbers seniors are thinking about the number of segments (neither of them figured out how to repeat) teammates with dynamic seconds over the idea: 2 3 3 2:2 3 3 2 3 3 2 3 2 #include <bits/stdc++.h>using namespace Std;long long Sum[1000010];long long A[100010];long long b[100010];int Main () { int t; cin>>t; while (t--) { memset (sum,0,sizeof (sum)); Long long N; scanf ("%lld", &n); b[0]=0; a[0]=0; For (long long i=1;i<=n;i++) { long long Shu; scanf ("%lld", &shu); b[i]=b[i-1]+ (I-sum[shu]) *shu; A[i]=a[i-1]+b[i]; sum[shu]=i; } cout<<a[n]<<endl; }}
12th Zhejiang Provincial Beauty of the B-Q Array