12th Zhejiang province Race b Beauty of Array

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.