CodeForces - 86D Powerful array

Score Matching(得分匹配) Score Matching(得分匹配)是一种统计学习方法,用于估计概率密度函数的梯度(即得分函数),而无需知道密度函数的归一化常数。这种方法由Hyvärinen在2005年提出,主要用于无监督学习,特别是在密度估计和生成模型中。 阅读详情

题目:给你n个数,m个询问,Ks为区间[l,r]中s出现的次数,求区间[l,r]中所有的Ks*Ks*s的和。

思路:莫队算法

代码:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<numeric>
using namespace std;
#define PI acos(-1.0)
#define LL __int64
#define ULL unsigned long long
#define INF 0x3f3f3f3f
#define mm(a,b) memset(a,b,sizeof(a))
#define PP puts("*********************");
template<class T> T f_abs(T a){ return a > 0 ? a : -a; }
template<class T> T gcd(T a, T b){ return b ? gcd(b, a%b) : a; }
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
// 0x3f3f3f3f3f3f3f3f
// 0x3f3f3f3f

const int maxn=1e6+50;
struct Ask{
    int L,R,id;
}ask[maxn];
LL ans[maxn];
int arr[maxn],num[maxn];//从1开始计数
int n,m,siz;//n个数,m个询问,块的大小
bool cmp(Ask a,Ask b){
    if(a.L/siz!=b.L/siz) return a.L/siz<b.L/siz;
    else return a.R<b.R;
}
void solve(){
    LL temp=0;
    mm(num,0);
    int L=1,R=0;
    for(int i=1;i<=m;i++){
        while(R<ask[i].R){
            R++;
            temp-=(LL)num[arr[R]]*num[arr[R]]*arr[R];
            num[arr[R]]++;
            temp+=(LL)num[arr[R]]*num[arr[R]]*arr[R];
        }
        while(R>ask[i].R){
            temp-=(LL)num[arr[R]]*num[arr[R]]*arr[R];
            num[arr[R]]--;
            temp+=(LL)num[arr[R]]*num[arr[R]]*arr[R];
            R--;
        }
        while(L<ask[i].L){
            temp-=(LL)num[arr[L]]*num[arr[L]]*arr[L];
            num[arr[L]]--;
            temp+=(LL)num[arr[L]]*num[arr[L]]*arr[L];
            L++;
        }
        while(L>ask[i].L){
            L--;
            temp-=(LL)num[arr[L]]*num[arr[L]]*arr[L];
            num[arr[L]]++;
            temp+=(LL)num[arr[L]]*num[arr[L]]*arr[L];
        }
        ans[ask[i].id]=temp;
    }
}
int main(){

    while(~scanf("%d%d",&n,&m)){
        for(int i=1;i<=n;i++)
            scanf("%d",&arr[i]);
        for(int i=1;i<=m;i++){
            ask[i].id=i;
            scanf("%d%d",&ask[i].L,&ask[i].R);
        }
        siz=(int)sqrt(n*1.0);
        sort(ask+1,ask+m+1,cmp);
        solve();
        for(int i=1;i<=m;i++)
            printf("%I64d\n",ans[i]);
    }
    return 0;
}


【keil5和STC-ISP】保姆级下载安装教程 点击下载中的产品下载。然后就会看到如下界面:可以看到,提供了针对不同芯片架构的四套独立开发工具。:你使用的51单片机,其核心就是。C51套件里的编译器是专门为这个架构优化的。:如果安装了MDK-Arm,你在创建新项目时将像“AT89C51”这样的51系列芯片型号,无法进行开发。进入如下界面:双击下载 → 双击运行安装 → 同意协议并下一步 → 使用默认安装路径 → 完成安装。 阅读详情

相关推荐

机器人视觉实战:用OpenCV搞定手眼标定(附完整C++代码)

本文详细介绍了使用OpenCV实现机器人视觉中的手眼标定技术,包括核心算法、工业场景优化及完整C++代码示例。通过解析坐标系转换问题,提供从数据采集到标定验证的全流程解决方案,帮助开发者在复杂工业环境中实现高精度机械臂与视觉系统的协同作业。

weixin_29306571的博客 487

Codeforces 86D.Powerful array(莫队)

给出n个数,m组询问,每组询问给出一段区间,输出区间内每个位置的val和,val的定义为该位置的数的值乘该位置上的数在区间内出现过的次数的平方。莫队板子题,对每个区间的数进行扫过去暴力维护。

xinchu0309的博客 306

C#实践项目1

需求: 在CAD内实现两个坐标系的转换。 转换方式为文件内的所有图形从一个坐标系下的坐标,转换到另一个坐标系下的坐标。 进行坐标转换后,仅仅是坐标发生改变,图层、样式等等不会发生变化。

weixin_51182789的博客 5337

Codeforces 86D:Powerful array

D. Powerful array time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output An array of positive integers a1, a2, ...

650

Unity3d实现红外热成像效果

1.将需要在红外图像中高亮的物体设置到图层PostProcessing。 2.新建一个相机CameraHighLight,设置其Culling Mask为PostProcessing,也就是在这个相机中只有PostProcessing图层的物体可见。 3.新建一个RenderTexture,命名为HightLightRt,将CameraHighLight的Target Texture设HightLightRt。 4.新建一个相机Camera2,这个相机用于显示其他物体。 接下来将CameraHigh

zouxin_88的专栏 8336

华为OD机试2025A卷 - 用户调度问题(Java & Python& JS & C++ & C )

题目要求每个用户依次选择当前所能选择的最小资源消耗策略,并且若有多个策略的资源消耗相同,则选择最后一个策略。每个用户的选择是独立的,只考虑该用户的策略和相邻用户的约束,不考虑整个调度序列的全局资源消耗。每个用户根据自己的当前状态(即自己的三种选择的资源消耗)做出局部最优选择:在当前可选的策略中,选择消耗最小的那个。如果有多个最小值,则选择最后一个(根据题意)。这一选择是局部的最优,即在当下最有利的选择,但并不保证最终的整体系统资源消耗是最小的。

算法大师! 1万+

cf86d

http://www.elijahqi.win/archives/389 D. Powerful array time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output An array of positive inte...

Elijahqi 413

信奥赛C++提高组csp-s之线段树详解

信奥赛C++提高组csp-s之线段树详解

王老师青少年编程 931

胜利Victor 86E 手持万用表 上位机开发 labview

最近入手了一个胜利的万用表,86E,300多大洋。根据描述,自带RS232接口的,心想这个万用表好啊,可以接到电脑上做一些带记录功能的测量了。可入手后才发现似乎不是这样的。

lineter的专栏 8739

YOLOv13改进策略【损失函数篇】| 2024 引进Focaler-IoU损失函数 加强边界框回归 (Focaler-DIoU、Focaler-GIoU、Focaler-CIoU)

本文记录的是改进YOLOv13的损失函数,将其替换成。现有研究通过利用边界框之间的几何关系来提高回归性能,但忽略了困难样本和简单样本分布对边界框回归的影响。不同检测任务中困难样本和简单样本的分布不同,对于简单样本占主导的检测任务,关注简单样本的边界框回归有助于提高检测性能;对于困难样本比例较高的检测任务,需要关注困难样本的边界框回归。,提高检测器在不同检测任务中的性能。实现的。

Limiiiing的博客 873

Codev与Zemax相互转化

Codev与Zemax相互转化

weixin_72050316的博客 1053

CodeForces 86D Powerful array 莫队算法

题目:http://codeforces.com/problemset/problem/86/D 题意:给定一个数组,每次询问一个区间[l, r],设某个元素i出现的次数为num[i],求区间内元素num[i] ^ 2 * i的和 思路:莫队算法简单题,元素范围为[1, 1000000],要离散化一下, 不然会超时。。。 #include #include #include #incl

弱智就要多努力 734

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

codeforces 86D,Powerful array 莫队

codeforces 86D,Powerful array 莫队 传送门:https://codeforces.com/contest/86/problem/D 题意: 给你n个数,m次询问,每次询问问你在区间l,r内每个数字出现的次数的平方于当前这个数的乘积的和 题解: 莫队算法 思路: 根据平方和公式我们知道 \[ (a+1)^2=a^2+2a...

buerdepepeqi的CSDN博客 226

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

CodeForces - 86D D. Powerful array —— 莫队算法

题目链接:http://codeforces.com/problemset/problem/86/D D. Powerful array time limit per test 5 seconds memory limit per test 256 megabytes input standard input output stan

A man can be destroyed, but not defeated. 383

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

codeforces 86D Powerful array 莫队

https://vjudge.net/problem/CodeForces-86D 题目大意:nnn个元素的数组,mmm个询问(l,r)(l,r)(l,r),输出[l,r][l,r][l,r]的价值总和。如果一个数sss在[l,r][l,r][l,r]内出现了cntcntcnt次,那么这个数的价值就等于cnt∗cnt∗scnt*cnt*scnt∗cnt∗s。 思路:莫队板题呀。一看到可以离线,而且...

xiji333的博客 213

codeforces 86D. Powerful array(莫队算法)

An array of positive integers a1, a2, ..., an is given. Let us consider its arbitrary subarray al, al + 1..., ar, where 1 ≤ l ≤ r ≤ n. For every positive integer s denote by Ks the number of o

ZAQ的博客 2482

CodeForces - 86D Powerful array 莫队

CodeForces - 86D Powerful array 题意: 有n个元素的数组,m条查询,每一次输出区间 [L , R] 内每个数出现次数的平方乘以这个数本身的和。 8 3 1 1 2 2 1 3 1 1 2 7 1 6 2 7 例如第一条查询语句 1出现三次,2出现两次,3出现一次 cnt[1]=3 , cnt[2]=2 , cnt[3]=1 结果为:cnt[1]^2...

没有梦想何以远行 187

codeforces 86 D. Powerful array(莫队)

题目链接:https://codeforc.es/contest/86/problem/D 思路:模板题 #include <cstdio> #include <cstdlib> #include <cassert> #include <cstring> #include <bitset> #include <cmath&gt...

llmxby 242

Codeforces 86D Powerful array 莫队算法 分块

D. Powerful array time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output An array of positive integers a1, a2, ...

J. Cole 359

codeforces 86 D Powerful array

codeforces 86 D powerful array

unicornt的博客 447

【分块】Codeforces 86d Powerful array

通道 题意:询问[l,r]区间的权和,权定义为sum(k^2*a[i]),k表示a[i]出现的次数 思路:区间每增加一个a[i],增量是(2*x+1)*a[i],因为(x+1)^2*a[i] = (x^2 +2*x + 1)*a[i] 分块排序即可,块内按r排序 代码: #include <cstdio> #include <algorithm&gt...

125

CodeForces-86D Powerful array 莫队

CodeForces-86D Powerful array 题意: 给定一个区间计算power值, power[l, r] = sigma(sum[pi]*sum[pi]*pi). 分析: 莫队来做, 对于add操作, 要累加的值为(sum[a[x]]*2 + 1)*a[x], del操作减去就行. 这个规律很好发现. 这道题卡常, 乘法用位操作替代. 输出一定要I64d, 否则TLE. 代码:...

YancyKahn 332

Codeforces 86D Powerful Array [莫队算法]

D. Powerful array time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard outputAn array of positive integers a1, a2, …, an is given. Let us consider

C'est la vie. 522

CodeForces 86 D Powerful array 莫队

Powerful array 题意:求区间[l, r] 内的数的出现次数的平方 * 该数字。 题解:莫队离线操作, 然后加减位置的时候直接修改答案就好了。 这个题目中发现了一个很神奇的事情,本来数组开1e6大小就直接过了4100+ms, 想测试一下inline,顺手把空间砍成了刚好够用,然后跑的更慢了 4700+ms,删了inline之后T了,到现在也不知道发生了啥。 如果有大牛...

dengpangbu3703的博客 111
上一篇: bzoj - 2038 小Z的袜子(hose)
下一篇: HDU - 5145 NPY and girls
我不会额
博客等级 码龄11年 2粉丝 173原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址