12th Zhejiang Provincial competition question B Beauty of Array, 12th Zhejiang Province
Beauty of Array Time Limit: 2 Seconds Memory Limit: 65536 KB
Edward has an arrayAWithNIntegers. He defines the beauty of an array as the summation of all distinct integers in the array. Now Edward wants to know the summation of the beauty of all contiguous subarray of the arrayA.
Input
There are multiple test cases. The first line of input contains an integerTIndicating the number of test cases. For each test case:
The first line contains an integerN(1 <=N<= 100000), which indicates the size of the array. The next line containsNPositive integers separated by spaces. Every integer is no larger than 1000000.
Output
For each case, print the answer in one line.
Sample Input
351 2 3 4 532 3 342 3 3 2
Sample Output
1052138 question: Self-translation. What I was thinking at the time was that the tree-like number student thought about the number of line segments (I didn't even think about how to repeat them). My teammates used the dynamic second to pass the train of thought: 2 3 3 3 3 3 3 3 2 2 2 2 2 before each Subtraction#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; }}