博客
关于我
魔法序列-upc
阅读量:282 次
发布时间:2019-03-01

本文共 1533 字,大约阅读时间需要 5 分钟。

题目描述

小E为了完成公主的任务,需排布魔法阵,从中获得法力。
简单起见,魔法阵可以看成一个长度为n的序列。序列从左到右都摆放了一张符卡,符卡有一个强度ai。法术的释放要每个元素相互配合,取得共鸣效果。一个由一些符卡组成的咒语的魔力值为这个咒语中所有符卡的强度的最大公因数乘以符卡的个数。
小E会从魔法阵中选择一段连续符卡区间[l,r](包括l,r端点),作为吟唱的咒语。她想知道,咒语最大的魔力值是多少。
输入
第一行一个整数n,表示符卡个数。
第二行n个正整数,第i个数表示符卡的强度ai。
输出
输出一个整数,表示最大的魔力值。
样例输入 Copy

530 60 20 20 20

样例输出 Copy

80
提示
样例解释
选择区间[2,5],其中gcd(60,20,20,20)=20,故魔力值为(5-2+1)*20=80。
二话不说,先放上友链

大佬的想法

在这里插入图片描述
在这里插入图片描述
代码和某巨巨差不多,只是注释多了点

#include 
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define wuyt maintypedef long long ll;#define HEAP(...) priority_queue<__VA_ARGS__ >#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > >template
inline T min(T &x,const T &y){ return x>y?y:x;}template
inline T max(T &x,const T &y){ return x
>=1; x=(x*x); } return res;}ll maxx=-1;ll minn=inf;ll num2[maxn];ll num[maxn];ll res,ans;int sum=0;map
mp;map
mpt;vector
vet;priority_queue
,greater
> xiaogen;queue
duilie;priority_queue
,less
> que;///https://www.pasteme.cn/35934int main(){ int n=read; for(int i=1;i<=n;i++) num[i]=read; ans=-1; for(int i=1;i<=n;i++)///right { mp=mpt,mpt.clear(); ans=max(ans,num[i]);///本身的最大 if(mpt.count(num[i])==0) mpt[num[i]]=i; for(auto it=mp.begin();it!=mp.end();it++){ res=gcd(num[i],it->first);///it->first里面是存储的数,it->second里面是下标对于mpt来说 ///对于前面区间的更新已经通过mp=mpt更新,所以对于mp亦是如此 ans=max(ans,res*(i-(it->second)+1)); ///test: ///cout<
<
second; else if(mpt.count(res)!=0) mpt[res]=min(mpt[res],it->second); } } cout<
<

转载地址:http://kloo.baihongyu.com/

你可能感兴趣的文章
Mysql5.7版本单机版my.cnf配置文件
查看>>
mysql5.7的安装和Navicat的安装
查看>>
mysql5.7示例数据库_Linux MySQL5.7多实例数据库配置
查看>>
Mysql8 数据库安装及主从配置 | Spring Cloud 2
查看>>
mysql8 配置文件配置group 问题 sql语句group不能使用报错解决 mysql8.X版本的my.cnf配置文件 my.cnf文件 能够使用的my.cnf配置文件
查看>>
MySQL8.0.29启动报错Different lower_case_table_names settings for server (‘0‘) and data dictionary (‘1‘)
查看>>
MYSQL8.0以上忘记root密码
查看>>
Mysql8.0以上重置初始密码的方法
查看>>
mysql8.0新特性-自增变量的持久化
查看>>
Mysql8.0注意url变更写法
查看>>
Mysql8.0的特性
查看>>
MySQL8修改密码报错ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
查看>>
MySQL8修改密码的方法
查看>>
Mysql8在Centos上安装后忘记root密码如何重新设置
查看>>
Mysql8在Windows上离线安装时忘记root密码
查看>>
MySQL8找不到my.ini配置文件以及报sql_mode=only_full_group_by解决方案
查看>>
mysql8的安装与卸载
查看>>
MySQL8,体验不一样的安装方式!
查看>>
MySQL: Host '127.0.0.1' is not allowed to connect to this MySQL server
查看>>
Mysql: 对换(替换)两条记录的同一个字段值
查看>>