浙江省第十二届省赛 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;
}

原文地址:https://www.cnblogs.com/GHzz/p/8597221.html

时间: 2024-08-03 08:39:10

浙江省第十二届省赛 Beauty of Array的相关文章

Little Sub and Traveling(杭师大第十二届校赛E题) 欧拉回路

题目传送门 题目大意: 从0出发,每次只能跳到(i*2)%n或者(i*2+1)%n,求字典序最大的哈密顿回路. 思路: 首先n为奇数时无解,先来证明这一点. 先假设n为奇数,若要回到原点,则必定有一步是$a%n=0$,则$a=kn(k为整数)$. 我们先假设a是通过$2x$的方式得到的,即$kn=2*x$,由于此时$n$为奇数,则k必定为偶数,由于$n>x$,所以$k<2$,k又不能等于0,所以此时k无解,a不是通过$s*x$的方法得到的 那么$kn=2*x+1$,k为奇数,则$k=1  ,a

第十二届湖南省赛 A - 2016 ( 数学,同余转换)

给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) 的数量: 1. 1≤a≤n,1≤b≤m; 2. a×b 是 2016 的倍数. Input 输入包含不超过 30 组数据. 每组数据包含两个整数 n,m (1≤n,m≤10 9). Output对于每组数据,输出一个整数表示满足条件的数量.Sample Input 32 63 2016 2016 1000000000 1000000000 Sample Output 1 30576 7523146895502644 Hint 思路:

18年第十二届东北四省赛

18年第十二届东北四省赛 5.19晚上的东北四省赛的热身赛老师说不用参加,当时白天打了一场之后,也确实脑壳疼QAQ: 5.20很吉利的日期啊,9.30-2.30,还是一样的分工读题,外加看榜,然后很幸运,两道水题,一道A,一道K,队友直接听我们的上去敲,然后交的时候比较谨慎,0罚时,连A两题,然后挂机4小时40分钟?!然后我们讨论了B,然后就一直B....当时觉得B转换为二进制没问题,后来WA,发现有个地方爆Long long,然后又发现有个地方爆Long long,然后把乘法改成除法感觉不会爆

12th浙江省省赛 B题 Beauty of Array

Beauty of Array Time Limit: 2 Seconds      Memory Limit: 65536 KB 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

第十二届全国人民代表大会《政府工作报告》全文

第十二届全国人民代表大会<政府工作报告>全文 第十二届全国人民代表大会<政府工作报告>全文 温jia宝 2013年3月5日 温jia宝: 现在,我代表国务院,向大会报告过去五年的政府工作,并对今年工作提出建议,请各位代表审议,并请全国政协委员提出意见.[09:05] 过去五年工作回顾[09:06] 第十一届全国人民代表大会第一次会议以来的五年,是我国发展进程中极不平凡的五年.我们有效应对国际金融危机的严重冲击,保持经济平稳较快发展,国内生产总值从26.6万亿元增加到51.9万亿元,

2016年湖南省第十二届大学生计算机程序设计竞赛---Parenthesis(线段树求区间最值)

原题链接 http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1809 Description Bobo has a balanced parenthesis sequence P=p1 p2…pn of length n and q questions. The i-th question is whether P remains balanced after pai and pbi  swapped. Note that questions ar

政协十二届五xq

●赠送园区专属活动展位两个: [改变贫困地区面貌是我们的历史责任] 十二届全国人大常委会第二十六次会议分组审议全国人大常委会工作报告稿 从2016年10月开始,永兴县认真开展"三资"清查,规范村级财务,组织4个调研督查组,对各乡镇清理情况进行专项督查:查纠各村居(社区)在执行党的路线方针政策.六大纪律.遵守法律法规等方面存在的问题,特别是针对一些城郊村和富裕村.贫困村,以及群众反映强烈.矛盾集中突出的村居(社区),深入细致地来一次"大体检",认真排查问题线索.截至目

2019第二十二届科博会-北京人工智能大会

2019第二十二届北京科博会-国际人工智能大会由×××科学技术部.×××知识产权局.北京市人民政府.中国贸易促进委员会主办,第二十二届北京科博会-国际人工智能大会开幕式在北京国际展览中心举行,一场AI盛宴正式隆重拉开帷幕. 此次展览会以"智慧科技·能创未来"为主题,展出面积超过10000㎡,三百余家AI企业参与,其中不乏AI行业极具盛名的企业,携其产品和技术莅临现场,全面展示了人工智能技术落地的新成果,详解人工智能在各领域应用落地的实施路径,共同诠释了一个核心-人工智能如何更好地服务于

2019第二十二届北京国际科技产业博览会

中国国际贸易促进委员会 ---国家级年度科技盛会---国际×××流交易平台---超强势媒体传播阵容2019第二十二届北京国际科技产业博览会THE 22ST CHINA BEIJING INTERNATIONAL HIGH-TECH EXPO 时间:2019年10月24日--27日 地点:北京·中国国际展览中心(老馆)主办单位: ×××科学技术部? ××××××中国国际贸易促进委员会? 北京市人民政府支持单位:×××商务部 ×××国有资产监督管理委员会×××教育部 ×××工业和信息化部中国科学技术