题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4648

  求遍前缀和,然后扫描标记下就可以了。。。

 //STATUS:C++_AC_453MS_1792KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,102400000")
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef __int64 LL;
typedef unsigned __int64 ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const int MOD=,STA=;
const LL LNF=1LL<<;
const double EPS=1e-;
const double OO=1e30;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End struct Node{
int s,id;
bool operator < (const Node& a)const {
return s!=a.s?s<a.s:id<a.id;
}
}st[N];
int num[N],sum[N];
int n,m; int binary(int l,int r,int tar)
{
int mid;
while(l<r){
mid=(l+r)>>;
if(st[mid].s<=tar)l=mid+;
else r=mid;
}
return l;
} int main(){
// freopen("in.txt","r",stdin);
int i,j,ans,w;
while(~scanf("%d%d",&n,&m))
{
sum[]=;
for(i=;i<=n;i++){
scanf("%d",&num[i]);
sum[i]=((sum[i-]+num[i])%m+m)%m;
st[i].s=sum[i];
st[i].id=i;
}
sort(st+,st+n+);
ans=;
for(i=;i<n && ans<n-i;i++){
w=binary(,n+,sum[i]);
if(st[w-].s==sum[i] && st[w-].id>i)ans=Max(ans,st[w-].id-i);
} printf("%d\n",ans);
}
return ;
}

最新文章

  1. 一个简单的路由,用javascript实现
  2. Python自动化之django视图
  3. jQuery EasyUI CheckBoxTree的级联选中
  4. Linux 将文件夹下的所有文件复制到另一个文件里
  5. 有强迫症的我只能自己写一个json格式化工具
  6. call、apply、bind的区别
  7. css3学习总结4--CSS3背景
  8. Base Pattern基本模式_Gateway入口
  9. 2.MySQL入门基本操作初体验
  10. 用Delphi获取当前系统时间
  11. AsyncHttpClient 开源框架學習研究
  12. 最受欢迎的8位Java大师
  13. NetAnalyzer2016使用方法
  14. Android Weekly Notes Issue #250
  15. 静态变量和Session
  16. 四.GC —三分钟认识JAVA回收机制(Java Garbage Collection)
  17. 原创:LNMP架构部署个人博客网站 禁止转载复制
  18. C#写鞍点问题
  19. ubuntu only enable left click
  20. iOS 推荐几篇关于Objective-c 动态语言的文章

热门文章

  1. MySQL性能优化的21个最佳实践
  2. JAVA面试题:String 堆内存和栈内存
  3. linux 修改命令行编码 乱码解决方案
  4. adobe 蛋疼的套装, 想安装一个Flash Professional CS6,标准版还没有...
  5. 阿里巴巴Java面试题
  6. [Unity菜鸟] 协程Coroutine
  7. WampServer安装图解教程
  8. VLAN是什么
  9. DataTable ,XML和JSON相互转化
  10. matlab 在代码中,显示错误,退出程序