首页 > 其他分享 >CF889E Mod Mod Mod

CF889E Mod Mod Mod

时间:2022-09-22 22:23:41浏览次数:63  
标签:CF889E int void times read inline Mod

link

Solution

又被踩爆了。。。/kk

注意到对于似乎对于值域上的一段,它的贡献总是一个一次函数形式,因为一开始初始值 \(-1\) 的话,在没有影响后面模出 \(0\) 的情况下,贡献会 \(-n\)。

所以我们可以考虑对这条直线进行 dp,设 \(f_{i,j}\) 表示对于前面 \(i\) 个数 \(\ge j\) 的时候贡献至少为 \(i\times j+f_{i,j}\) 的 \(f_{i,j}\) 最大值。

我们考虑如何转移。首先对于 \(j<a_{i+1}\) 的时候,显然存在 \(f_{i+1,j}=f_{i,j}\)。

然后考虑到,对于 \([0,j\mod{a_{i+1}}]\) 这一段,转移即是 \(f_{i+1,j\mod {a_{i+1}}}=f_{i,j}+i\times (j-j\mod {a_{i+1}})\)。

接着考虑 \([0,a_{i+1}-1]\) 这一段,可以发现最大模 \(a_{i+1}\) 等于 \(a_{i+1}-1\) 的值为 \(y=a_{i+1}-1+a_{i+1}\times \lfloor\frac{j-a_{i+1}+1}{a_{i+1}}\rfloor\),那么变化即是:

那么转移即是:\(f_{i+1,a_{i+1}-1}=f_{i,j}+i\times a_{i+1}\times \lfloor\frac{j-a_{i+1}+1}{a_{i+1}}\rfloor\) 。

可以用 map 去维护这一过程。

然后考虑复杂度如何计算,可以发现对于一个状态(指第 \(i\) 次插入的 \(a_{i}-1\) ),一次转移值域减少至少一半,所以复杂度即是: \(\Theta(n\log n\log A)\)。

Code

#include <bits/stdc++.h>
using namespace std;

#define Int register int
#define int long long
#define MAXN 200005

template <typename T> inline void read (T &t){t = 0;char c = getchar();int f = 1;while (c < '0' || c > '9'){if (c == '-') f = -f;c = getchar();}while (c >= '0' && c <= '9'){t = (t << 3) + (t << 1) + c - '0';c = getchar();} t *= f;}
template <typename T,typename ... Args> inline void read (T &t,Args&... args){read (t);read (args...);}
template <typename T> inline void write (T x){if (x < 0){x = -x;putchar ('-');}if (x > 9) write (x / 10);putchar (x % 10 + '0');}
template <typename T> inline void chkmax (T &a,T b){a = max (a,b);}
template <typename T> inline void chkmin (T &a,T b){a = min (a,b);}

int n,s[MAXN];
map <int,int> f;

signed main(){
	read (n);
	for (Int x = 1;x <= n;++ x) read (s[x]);
	f[s[1] - 1] = 0;
	for (Int i = 2;i <= n;++ i)
		for (auto it = f.lower_bound (s[i]);it != f.end();f.erase (it ++)){
			int x = it -> first,y = it -> second;
			chkmax (f[s[i] - 1],y + (i - 1) * s[i] * ((x - s[i] + 1) / s[i]));
			chkmax (f[x % s[i]],y + (i - 1) * (x - x % s[i]));
		}
	int ans = 0;
	for (auto it = f.begin();it != f.end();++ it){
		int x = it -> first,y = it -> second;
		chkmax (ans,x * n + y);
	}
	write (ans),putchar ('\n');
	return 0;
}

标签:CF889E,int,void,times,read,inline,Mod
From: https://www.cnblogs.com/Dark-Romance/p/16721049.html

相关文章

  • chmod 报错 changing permissions of 'xxx': Operation not permitted
    chmod报错changingpermissionsof'xxx':Operationnotpermitted问题使用root创建了一个子用户,在home目录下创建对应的文件夹更改文件夹的chown时报错解决ch......
  • 类型推导--Effective modern C++ 学习笔记
    类型推导--EffectivemodernC++学习笔记auto和template虽然用起来很爽,但是作为程序员我们应该了解C++编译器做了哪些事情,从而确实的保证整套机制能够顺利的运作。1.模......
  • .env[mode]文件中如何添加注释
    前言Vue-Cli允许我们在项目根目录创建.env.[mode]文件来设置一些打包编译的启动参数,通过执行脚本的时候加mode参数,指定不同环境需要加载的配置文件形如:.env.prodNODE_......
  • AttributeError: module 'backend_interagg' has no attribute 'FigureCanvas'. Did y
     plt报错像是下面这样子File"C:\Users\abc\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\pyplot.py",line191,in_get_required_inter......
  • bug记录:this is incompatible with sql_mode=only_full_group_by
    java.sql.SQLSyntaxErrorException:Expression#8ofSELECTlistisnotinGROUPBYclauseandcontainsnonaggregatedcolumn'environment.t1.so2'whichisnotfu......
  • Vue---数据绑定(v-model)
    <!DOCTYPEhtml><html> <head> <metacharset="utf-8"> <title></title> <!-- 一。单向双向数据绑定 1.单向数据绑定:页面上输入内容(页面上展示数据)----不出......
  • linux命令:chmod(常用方法详解)
     linuxchmod命令是在日常运维中比较常用的命令之一,对文件管理比较重要,如设置web目录时需设置特定的权限以保证服务器安全。提示:在写完shell脚本后,我们一般需要给这脚本设......
  • git submodule子模块操作
    背景为什么使用子模块,因为需要使用其他人维护的公共组件,但这些组件并不是以包或库的形式使用的。所以采用子模块的形式,无论是自己修改还是拉取也很方便。子模块操作增加......
  • qmlRegisterType 注册C++类型出现 module not fount
    使用 qmlRegisterSingletonType或 qmlRegisterType想QML注册C++类,按照使用文档上方法添加如下:qmlRegisterSingletonType<CProtoInfoModel>("LdpModel",1,0,"p......
  • css box model
        HTML:  css:  效果: 一起设置: border:widthstylecolor;exaple:  border:mediumdashedgreen; border-radius可以把四周钝化:  ......