浙江省第十二届省赛 Beauty of Array

Posted ghzz

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了浙江省第十二届省赛 Beauty of Array相关的知识,希望对你有一定的参考价值。

Description

Edward has an array A with N integers. 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 array A.

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 <= 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 in one line.

Sample Input

3
5
1 2 3 4 5
3
2 3 3
4
2 3 3 2

Sample Output

105
21
38

题意:

定义Beauty数是一个序列里所有不相同的数的和,求一个序列所有字序列的Beauty和

题解:

按先后顺序将每个元素加入队列 然后计算

例:如果array【1,2,3】

1:    1              dp = 1;

2:    1 2

          2          dp = 1+2*2;

3:    1 2 3

     2 3

     3    dp = 5+3*3;

以此类推,如果有相同元素 emmmmm 自己去推吧 -.-

代码:

#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <cstdlib>
#include <string>
using namespace std;
#define is_lower(c) (c>=‘a‘ && c<=‘z‘)
#define is_upper(c) (c>=‘A‘ && c<=‘Z‘)
#define is_alpha(c) (is_lower(c) || is_upper(c))
#define is_digit(c) (c>=‘0‘ && c<=‘9‘)
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define IO ios::sync_with_stdio(0);\
    cin.tie(0);    cout.tie(0);
#define For(i,a,b) for(int i = a; i <= b; i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
const ll inf=0x3f3f3f3f;
const double EPS=1e-10;
const ll inf_ll=(ll)1e18;
const ll maxn=100005LL;
const ll mod=1000000007LL;
const int N = 1000000+5;
int ans [N];int main()
{
    IO
    int T;
    cin>>T;
    while(T--)
    {
        int n;
        memset(ans,0,sizeof(ans));
        cin>>n;
        int m = 0;
        ll res = 0,dp = 0;
        For(i,1,n){
            int x;
            cin>>x;
                dp += x*(i-ans[x]);
            res += dp;
            ans[x] = i;
        }
        cout<<res<<endl;
    }
    return 0;
}

 

以上是关于浙江省第十二届省赛 Beauty of Array的主要内容,如果未能解决你的问题,请参考以下文章

《蓝桥杯真题》:2.第十二届省赛

《蓝桥杯真题》:2021单片机省赛第一场(第十二届第一场)

备战第十二届蓝桥杯电子类《EDA设计与开发》国赛

蓝桥杯嵌入式——第十二届蓝桥杯嵌入式第一场省赛

第十二届蓝桥杯单片机省赛程序设计总结

第十二届蓝桥杯单片机省赛程序设计总结