[BZOJ3544][ONTAK2010]Creative Accounting(数学相关+set)
来源:互联网 发布:最大公约数 方法 知乎 编辑:程序博客网 时间:2024/06/08 09:13
题目描述
传送门
题解
一段区间的sigma可以转化为前缀和相减
而如果将前缀和都取模m意义下那么所有的都变成了1..m-1中的一个数
那么如果当前的前缀和为x,如何查询x-?的最大值
如果之前的前缀和有比x大的数y,那么答案一定为(x-y)%m
否则为x%m
x-y<0 -> (x-y)%m=m-(y-x)
y<=m -> m-(y-x)>=x
所以实际上就是查询一下是否有比x大的数
那我们拿treap/splay什么的随便维护一下就行了
当然set随便水
代码
#include<algorithm>#include<iostream>#include<cstring>#include<cstdio>#include<cmath>#include<set>using namespace std;#define LL long longconst LL inf=1000000000000000001LL;int n;LL m,x,sum,now,ans;set <LL> s;int main(){ scanf("%d%lld",&n,&m); ans=0;sum=0; s.insert(0);s.insert(inf); for (int i=1;i<=n;++i) { scanf("%lld",&x);x=(x%m+m)%m; sum=((sum+x)%m+m)%m;s.insert(sum); if (*s.upper_bound(sum)!=inf) now=*s.upper_bound(sum); else now=*s.begin(); ans=max(ans,((sum-now)%m+m)%m); } printf("%lld\n",ans);}
0 0
- [BZOJ3544][ONTAK2010]Creative Accounting(数学相关+set)
- [bzoj3544][ONTAK2010]Creative Accounting(set)
- 【bzoj3544】【ONTAK2010】Creative Accounting【set】
- 【bzoj3544】[ONTAK2010]Creative Accounting
- BZOJ3544 [ONTAK2010]Creative Accounting 前缀和乱搞
- bzoj 3544: [ONTAK2010]Creative Accounting (STL)
- BZOJ 3544 ONTAK2010 Creative Accounting 平衡树
- bzoj 3544: [ONTAK2010]Creative Accounting treap
- BZOJ 3544 ONTAK 2010 Creative Accounting 贪心+平衡树
- Poj_2586 Y2K Accounting Bug(数学)
- 创造性思维(Creative Thinking)
- 645. Set Mismatch(数学)
- 数学相关(未完成)
- accounting货币汇率(前端)
- accounting
- poj 贪心相关之 Y2K Accounting Bug2586
- 数学相关(更新ing)
- [BZOJ3545][ONTAK2010]Peaks(splay启发式合并)
- love.graphics
- 了解 Spring Data JPA
- iOS 不同的崩溃类型
- 关于自定义控件在布局文件中使用时提示error: Error parsing XML: not well-formed (invalid token)错误的问题
- 《软件工程思想》读后感
- [BZOJ3544][ONTAK2010]Creative Accounting(数学相关+set)
- AS 二
- love.image
- 关于markdown,这里有需要知道的一切
- MaterialDesign之NavigationView和DrawerLayout实现侧滑菜单栏(抽屉)
- C#学习笔记之委托
- Axure之视频插入简单实例
- love.joystick
- 【opencv学习之六】opencv+Qt+Qzxing调取本地摄像头识别二维码