HBC260443LLLYYY的数字思维,贪心mex和gcd的乘积题解

你曾走过我的故事 算法基础篇 55 0
想要检验自己的编程水平?来试试全网最全C++题库,让您在挑战中不断进步。
给你一个长度为nnn的数列,求这个数列中连续区间的mexoperatorname{mex}mex乘gcdoperatorname{gcd}gcd的最大值是多少?关于mexoperatorname{mex}mex:区间的mexoperatorname{mex}mex被定义为区间中未出现的最小的非负整数,例如:。[2,2,1][2,2,1][2,2,1]的mexoperatorname{mex}mex是000,因为000不在这个区间中。关于gcdoperatorname{gcd}gcd:连续区间的最大公约数是指一个数列中相邻的若干个数字的最大公约数,同时也是最大能被区间中所有数整除的数,特殊的,对于任意非负整数xxx,gcd(0,x)=xoperatorname{gcd}(0,x)=xgcd(0,x)=x,gcd=xoperatorname{gcd}=xgcd=x,例如:

曾经的A,为何如今沦落成了C                                                     ——来自一场连续出三个妙妙签到题的良心出题人 给你一个长度为nnn的数列。求这个数列中连续区间的mex⁡operatorname{mex}mex乘gcd⁡operatorname{gcd}gcd的最大值是多少? 形式化的:定义f(l,r)=mex⁡(al,...,ar)×gcd⁡(al,...,ar) , l≤rf(l,r)=operatorname{mex}(a_l,...,a_r)times operatorname{gcd}(a_l,...,a_r) , lle rf(l,r)=mex(al​,...,ar​)×gcd(al​,...,ar​) , l≤r。求f(l,r)maxf(l,r)_{max}f(l,r)max​ 关于mex⁡operatorname{mex}mex:区间的mex⁡operatorname{mex}mex被定义为区间中未出现的最小的非负整数,例如: [2,2,1][2,2,1][2,2,1]的mex⁡operatorname{mex}mex是000,因为000不在这个区间中 [3,1,0,1][3,1,0,1][3,1,0,1]的mex⁡operatorname{mex}mex是222,因为000,111在这个区间中,而222不在这个数组中 [0,3,1,2][0,3,1,2][0,3,1,2]的mex⁡operatorname{mex}mex是444,因为000,111,222,333在这个区间中,而444不在这个数组中 关于gcd⁡operatorname{gcd}gcd:连续区间的最大公约数是指一个数列中相邻的若干个数字的最大公约数,同时也是最大能被区间中所有数整除的数。特殊的,对于任意非负整数xxx,gcd⁡(0,x)=xoperatorname{gcd}(0,x)=xgcd(0,x)=x,gcd⁡(x)=xoperatorname{gcd}(x)=xgcd(x)=x,例如: gcd⁡(6,4,3)=gcd⁡(gcd⁡(6,4),3)=gcd⁡(2,3)=1operatorname{gcd}(6,4,3)=operatorname{gcd}(operatorname{gcd}(6,4),3)=operatorname{gcd}(2,3)=1gcd(6,4,3)=gcd(gcd(6,4),3)=gcd(2,3)=1 gcd⁡(5,2,0)=gcd⁡(gcd⁡(5,2),0)=gcd⁡(1,0)=1operatorname{gcd}(5,2,0)=operatorname{gcd}(operatorname{gcd}(5,2),0)=operatorname{gcd}(1,0)=1gcd(5,2,0)=gcd(gcd(5,2),0)=gcd(1,0)=1 gcd⁡(5)=5operatorname{gcd}(5)=5gcd(5)=5

HBC260443LLLYYY的数字思维,贪心mex和gcd的乘积题解
-第1张图片-东莞河马信息技术
(图片来源网络,侵删)
想要在职场中立于不败之地?那就来试试全网最全C++题库,让您在练习中快速提升技能。

标签: HBC260443LLLYYY的数字思维 贪心mex和gcd的乘积题解