Beauty of Array(ZOJ3872)

AE与PR用强大滤镜Frischluft Flair v1.12汉化版 立即下载

这个是12th浙江省赛的一道题目,当时自己思考了好久才写出来的。

心疼自己,再次做到这道题的时候竟然写不来了,在此放出这道题。

以后自己写的题目一定要记得。

#include<bits/stdc++.h>
using namespace std;
int numpos[100005];//存的是每个数字的上一个位置
int a[100005];//数组
long long bits[100005];//当前数字能创造的贡献
int T,n;
long long ans,temp;
int main()
{
    cin >>T;
    while(T--)
    {
        cin>>n;
        ans=0;
        temp=0;
        memset(numpos,-1,sizeof(numpos));
        memset(a,0,sizeof(a));
        memset(bits,0,sizeof(bits));
        for(int i=0; i<n; i++) //数组
            cin>>a[i];

        for(int i=0; i<n; i++)
        {
            temp+=a[i];//temp暂存贡献
            if(numpos[a[i]]==-1)
            //如果这个数字第一次出现,那么对从0开始到这个位置都有贡献,所以a[i]*i,然后更新数字位置
            {
                numpos[a[i]]=i;
                temp+=i*a[i];
            }
            else
            //不是第一次出现,那么就对两个位置中间的数字有贡献
            {
                temp+=(i-numpos[a[i]]-1)*a[i];
                numpos[a[i]]=i;
            }
            bits[i]=temp;
        }
        //全加求和,需要注意的是,一定要long long 否则会溢出
        for(int i=0; i<n; i++)
        {
            ans+=bits[i];
        }
        cout<<ans<<endl;
    }
    return 0;
}


Android开发者必看:F2FS文件系统如何优化你的手机存储性能(附实测数据对比) 本文深入解析了F2FS文件系统如何针对闪存特性优化Android设备存储性能。通过对比ext4,F2FS采用追加写和冷热数据分离策略,将随机写转化为顺序写,显著提升写入速度并减少GC卡顿。实测数据显示,其在随机写入和SQLite事务等场景下性能提升显著,为开发者提供了优化应用IO性能的关键思路。 阅读详情

相关推荐

手把手教你低成本复刻大疆C板缓启动电路(附原理图与选型清单)

本文详细介绍了如何低成本复刻大疆C板缓启动电路,包括核心器件选型、电路搭建与调试实战、参数优化方法论及进阶改进思路。通过替代型号和优化设计,实现功能相近的缓启动电路,成本不到原方案的1/3,适合电子爱好者、在校学生和预算紧张的硬件工程师。

weixin_29197051的博客 402

Beauty of Array

Beauty of Array 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

素宇的博客 441

Ubuntu20.04 高效安装企业微信的完整指南

本文提供了在Ubuntu20.04系统上高效安装企业微信的完整指南,详细介绍了通过Deepin-wine环境运行Windows版企业微信的步骤和优化技巧。内容包括系统环境检查、依赖安装、企业微信包的获取与安装、首次运行配置及常见问题解决方案,帮助开发者在Ubuntu系统中流畅使用企业微信进行办公通讯。

weixin_42568801的博客 359

ACM-水题 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

不想宅的冷同学 1338

GT-Power柴油机瞬态性能仿真与优化——基于EGR-VGT耦合控制策略【附案例】

本文探讨了GT-Power在柴油机瞬态性能仿真与优化中的应用,重点分析了EGR-VGT耦合控制策略的实际效果。通过案例研究展示了如何通过仿真优化提升柴油机的动力响应速度和排放性能,为车辆工程领域的工程师提供了实用的技术参考。

green的博客 768

数十个锂电池充放电电路,锂电池充放电芯片

关乎锂电池供电的产品,在锂电池上,需要三个电路系统:1,锂电池保护电路,2,锂电池充电电路,3,锂电池输出电路。 内容目录: 单节的锂电池保护电路单节为3.7V锂电池(也叫4.2V)和3.8V锂电池(也叫4.35V) 单节的锂电池充电电路即锂电池保护板 单节的锂电池输出电路锂电池转换稳压输出为:1.2V,3.3V,5V,12V等等 两节的锂电池保护电路两节串联7.4V锂电池(也叫8.4V) 两节的锂电池充电电路即两节锂电池保护板 两节...

kuakewei123的博客 1万+

zoj 3872 Beauty of Array (数学题)

题意: 给出一个序列,然后问这个序所有子序列对应数值的和是多少,注意这个和是序列中不同的数的和。 题解: 这题我们可以这样分析,对于某个数,考虑这个数对总的结果的贡献是多少,于是根据这个方向去思考,加上一些实例的判断,发现可以用递推去求解。 #include #include #include #include #include #include #include #include

ACM之梦 640

MTK PE+2.0介绍

  PE+2.0介绍:   1.      PE+2.0的状态机: 2.      升压波形协议及编码规则: PE+2.0软件设计:   在充电器类型为标充且底层电量SOC在1%—95%之间时,开始PE+2.0升压充电器的检测:首先将VBUSreset至5V,之后发送8.5的current pattern再获取此时VBUS电压和8.5V比较,若其与8.5的差值绝对值在0.5之...

raydom07的博客 1万+

金融反作弊中的设备指纹

金融反作弊中的设备指纹

everlasting_188-java从业者 5453

【MicroPython编程-ESP32篇:设备驱动】-SHT31温度湿度传感器驱动

SHT31 是 Sensirion 的下一代温湿度传感器。 它建立在一个新的 CMOSens® 传感器芯片之上,该芯片是 Sensirion 新湿度和温度平台的核心。

视觉与物联智能 242

手把手教你学Simulink--电机电磁兼容与可靠性​场景示例:基于Simulink的电机轴电压与轴电流抑制仿真

本文带你完成了电机轴电压与轴电流抑制的Simulink仿真,实现了:✅ 揭示了共模电压 → 寄生电容 → 轴电压 → 轴承电蚀的完整链路✅ 搭建了含寄生参数的高频电机等效模型共模电压最小化PWM(源头抑制)dv/dt滤波器(路径阻断)轴接地(终端泄放) ✅ 通过仿真验证了轴电压从68 V降至<3 V的显著效果 ✅ 为高可靠性电机系统提供低成本、高效益的轴承保护方案。

MHD0815的博客 325

ZOJ 3872 Beauty of Array(DP)

ZOJ 3872 Beauty of Array 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

No Rain,No L'Arc~en~Ciel 475

2024年11月架构设计师综合知识真题回顾,附参考答案、解析及所涉知识点(一)

软考高级考试包含三个科目:信息系统综合知识、系统架构设计案例分析和系统架构设计论文。考试形式为机考。本文主要回顾2024年下半年(2024-11-10)系统架构设计师考试上午综合知识科目的选择题,同时附带参考答案、解析和所涉知识点。由于机考时题目顺序是打乱的,本文题目所标序号只为区分不代表实际顺序。综合知识。

一几文的编程学习笔记。 9304

Beauty of Array ZOJ - 3872

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 ...

小帅哥快来看啊的博客 242

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

ZOJ 3872 Beauty of Array(DP)

ZOJ 3872 Beauty of Array( DP思想 )

1037

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

zoj3872Beauty 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 arra

走一步再走一步 529

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

ZOJ 3872 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 arra

LZK1997的博客 404

ZOJ 3872 — Beauty of Array

原题:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3872 题意:求n个数的所有相邻的子数组的和,但重复的数字不加;     譬如:2 3 3 — 相邻子数组:2;3;3;23;33;233;     sum = (2)+(3)+(3)+(2+3)+(3)+(2+3)=  21; 思路:a[i]表示到第i

吧唧吧唧 576

ZOJ3872 Beauty Of Array

题目链接:http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5496 题意:给定一些数字,要求取连续的一段数,和为其中所有元素和(出现多次只算一次)。问所有取法的和的和。 思路:按照一个一个往里添加元素的思想,dp即可。具体的话设前i-1个元素(inclusive)不重复,i与第j个元素重复,则dp[i] = (

beihai2013 470

ZOJ 3872 Beauty of Array【数学】

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 ...

PinkAir的博客 248

D - Beauty of Array ZOJ - 3872

题意: 给你N个数让你求他的连续子序列的和若一个连续子序列中出现重复项就不算。。子序列2 3 3 的值为5 eg:  1 2 3 dp是从前慢慢往后走的。。。别急啊。。 dp[1]=包含 1  :1 dp[2]=包含 2  : 2     | 1 2 dp[3]=包含 3  : 3    | 2 3 | 1 2 3 ans=dp[1]+dp[2]+dp[3]; dp[i]=a[i

爱梦者的心之旅 334

ZOJ3872 Beauty of Array【DP】

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 intege...

weixin_33963189的博客 126

ZOJ 3872 Beauty of Array(数学)

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5520Edward 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...

1864

思维 ZOJ 3872 Beauty of Array

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 ...

guozuofeng的博客 176

【DP】ZOJ - 3872 Beauty of Array

Step1 Problem: 定义Beauty数是一个序列中所有不同数的和,求一个序列所有连续子序列的Beauty和 数据范围: 1&lt;=N&lt;=1e5, 0&lt;=序列值&lt;=1e6 Step2 Involving algorithms: DP Step3 Ideas: 状态dp[i] : 以第i个数结尾的子序列的和 pos[x]:...

ACMer 梁剑锋 的博客 270
上一篇: Mistwald(ZOJ3479)
下一篇: Wet Shark and Flowers(cf621C)
Linnnnnger
博客等级 码龄11年 71粉丝 79原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值