博客
关于我
D. Equalize the Remainders[模拟+set中lower_bound效率问题]
阅读量:527 次
发布时间:2019-03-08

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

题意:要求改变一个数组,使得模m后,结果为0,1,2,3,...,m-1都是n/m个,每次操作可以选择一个数+1,问至少执行多少次,并输出最终的数组

思路:模拟当前元素应该往哪个元素去改变

注意:std::set::lower_bound的复杂度为logN,而std::lower_bound的复杂度在set里是logn+n,原因大致是set是一颗平衡树,用普通的lower_bound会有额外的增量时间,具体的,不研究.

具体的,可以上stackoverflow 或者 cppreference 参考两个函数的API接差别.

#include
#define PI acos(-1.0)#define pb push_back#define F first#define S secondusing namespace std;typedef long long ll;const int N=4e5+5;const int MOD=1e9+7;int a[N],sum[N];int cnt[N];set
st;int main(void){ ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); int n,m; cin >>n >> m; for(int i=1;i<=m;i++) st.insert(i-1); const int need=n/m;// cout << need << endl; ll ans=0; for(int i=1;i<=n;i++){ cin >> a[i]; int mo=a[i]%m; int dest; if(mo>*st.rbegin()) dest=*st.begin(); else dest=*st.lower_bound(mo);// cout <
<<"~"<
<<" "<
<

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

你可能感兴趣的文章
Nginx下配置codeigniter框架方法
查看>>
Nginx中使用expires指令实现配置浏览器缓存
查看>>
Nginx之二:nginx.conf简单配置(参数详解)
查看>>
Nginx从入门到精通
查看>>
Nginx代理websocket配置(解决websocket异常断开连接tcp连接不断问题)
查看>>
Nginx代理初探
查看>>
nginx代理地图服务--离线部署地图服务(地图数据篇.4)
查看>>
Nginx代理外网映射
查看>>
Nginx代理模式下 log-format 获取客户端真实IP
查看>>
Nginx代理解决跨域问题(导致图片只能预览不能下载)
查看>>
Nginx代理访问提示ERR_CONTENT_LENGTH_MISMATCH
查看>>
Nginx代理配置详解
查看>>
Nginx代理静态资源(gis瓦片图片)实现非固定ip的url适配网络环境映射ip下的资源请求解决方案
查看>>
Nginx代理静态资源(gis瓦片图片)实现非固定ip的url适配网络环境映射ip下的资源请求解决方案
查看>>
nginx优化日志拒绝特定404请求写入
查看>>
Nginx使用proxy_cache指令设置反向代理缓存静态资源
查看>>
Nginx入门教程-简介、安装、反向代理、负载均衡、动静分离使用实例
查看>>
nginx反向代理
查看>>
Nginx反向代理
查看>>
nginx反向代理、文件批量改名及统计ip访问量等精髓总结
查看>>