BZOJ 3544 [ONTAK2010]Creative Accounting(set)
【题目链接】 http://www.lydsy.com/JudgeOnline/problem.php?id=3544
【题目大意】
找一段区间使得Σai mod m的值最大。
【题解】
首先计算前缀和顺序插入set,对于一个位置为右端点的数来说,
如果前缀的前缀和中有比其大的数,选择比其大的最小的那个计算用来更新答案一定最优
如果不存在,则选择set中最小的来计算更新答案。
【代码】
#include <cstdio>
#include <algorithm>
#include <set>
using namespace std;
const int N=200010;
typedef long long LL;
const LL INF=0x3f3f3f3f3f3f3f3f;
int n;
LL m,a[N],s[N];
int main(){
while(~scanf("%d%lld",&n,&m)){
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
a[i]=(a[i]%m+m)%m;
s[i]=(s[i-1]+a[i])%m;
}LL t=0;
LL ans=-INF; set<LL> st;
st.insert(0);
for(int i=1;i<=n;i++){
if(st.upper_bound(s[i])!=st.end())t=*st.upper_bound(s[i]);
else t=*st.begin();
ans=max((s[i]-t+m)%m,ans);
st.insert(s[i]);
}printf("%lld\n",ans);
}return 0;
}
BZOJ 3544 [ONTAK2010]Creative Accounting(set)的更多相关文章
- BZOJ 3544: [ONTAK2010]Creative Accounting( BST )
题意 : 一段序列 , 求一段子序列和取余 M 的最大值 其实是一道水题... 前缀和 , 然后就是找 ( sum( r ) - sum( l ) ) % M 的最大值 . 考虑一个 sum( r ) ...
- BZOJ 3544: [ONTAK2010]Creative Accounting [set]
给定一个长度为N的数组a和M,求一个区间[l,r],使得$(\sum_{i=l}^{r}{a_i}) mod M$的值最大,求出这个值,注意这里的mod是数学上的mod 这道题真好,题面连LaTeX都 ...
- bzoj 3544 [ONTAK2010]Creative Accounting 贪心
Description 给定一个长度为N的数组a和M,求一个区间[l,r],使得(\sum_{i=l}^{r}{a_i}) mod M的值最大,求出这个值,注意这里的mod是数学上的mod Input ...
- 【BZOJ3544】[ONTAK2010]Creative Accounting 前缀和+set
[BZOJ3544][ONTAK2010]Creative Accounting Description 给定一个长度为N的数组a和M,求一个区间[l,r],使得(\sum_{i=l}^{r}{a_i ...
- 【BZOJ】3709: [PA2014]Bohater(贪心)
http://www.lydsy.com/JudgeOnline/problem.php?id=3709 很水的题...但是由于脑洞小..漏想了一种情况.. 首先显然能补血的先杀.. 然后杀完后从补血 ...
- 【BZOJ】1251: 序列终结者(splay)
http://www.lydsy.com/JudgeOnline/problem.php?id=1251 不行..为什么写个splay老是犯逗,这次又是null的mx没有赋值-maxlongint.. ...
- bzoj 3118: Orz the MST(单纯形)
题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=3118 题意:给出一个图以及图中指定的n-1条边组成的生成树.每条边权值加1或者减去 ...
- BZOJ 2004 Bus 公交线路(矩阵)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2004 题意:小Z所在的城市有N个公交车站,排列在一条长(N-1)km的直线上,从左到右依 ...
- BZOJ 1503 郁闷的出纳员(splay)
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1503 题意:给出一个数列(初始为空),给出一个最小值Min,当数列中的数字小于Min时自动 ...
随机推荐
- (转)梯度方向直方图HOG(Histograms of Oriented Gradients )
HOG(Histograms of Oriented Gradients )梯度方向直方图 方向梯度直方图(Histogram of Oriented Gradient, HOG)特征是一种在计算机视 ...
- RabbitMq related
# RabbitMq related Integration of message queuing tools with systems is the usual solution to handle ...
- Apache2.4+Tomcat7 集群
Apache2.4+Tomcat7 集群: 1.下载并安装相对应的软件 apache下载地址:http://httpd.apache.org/ 这里使用apache2.4 tomcat下载地址:htt ...
- HTTPS加密通信原理及数字证书系统
https加密通信原理: 公钥私钥成对,公钥公之于众,私钥只有自己知道. 用公钥加密的信息只能由与之相对应的私钥解密. 甲给乙发送数据时,甲先用乙的公钥加密这段数据,再用自己的私钥对这段数据的特征数据 ...
- vmware安装ubuntu " Intel VT-x 处于禁用状态"
vmware安装ubuntu " Intel VT-x 处于禁用状态" http://jingyan.baidu.com/article/fc07f98976710e12ffe51 ...
- 自动化测试===uiautomator2类似appium
项目地址:https://github.com/openatx/uiautomator2 http://mp.weixin.qq.com/s/YKxwW-pL603Fll3QIWapVw https: ...
- rhel-server srpms iso
http://ftp.redhat.com/pub/redhat/linux/enterprise/7Server/en/ ftp://ftp.pslib.cz/pub/linux/redhat-cz ...
- 广度优先搜索--POJ迷宫问题
Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, ...
- FISCO-BCOS平台共识
FISCO-BCOS 应用于区块链的多节点并行拜占庭容错共识算法 看了下微众平台的wiki共识知识 学习下 ()内是自己的思考 参考: https://github.com/FISCO-BCOS/W ...
- 2017多校第6场 HDU 6096 String AC自动机
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6096 题意:给了一些模式串,然后再给出一些文本串的不想交的前后缀,问文本串在模式串的出现次数. 解法: ...