[USACO16JAN]子共七Subsequences Summing to Sevens
a[i]表示前缀和
如果a[i]%7==t&&a[j]%7==t
那么a[j]-a[i-1]一定是7的整数倍,
这样就o(n)扫一遍,不断更新答案就可以了。

#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstring>
#define inf 2147483647
#define For(i,a,b) for(register long long i=a;i<=b;i++)
#define p(a) putchar(a)
#define g() getchar()
//by war
//2017.10.12
using namespace std;
long long n;
long long a[];
long long p[];
long long x,l,ans;
void in(long long &x)
{
char c=g();x=;
while(c<''||c>'')c=g();
while(c<=''&&c>='')x=x*+c-'',c=g();
}
void o(long long x)
{
if(x>)o(x/);
p(x%+'');
}
int main()
{
in(n);
For(i,,n)
{
in(x);
a[i]=x+a[i-];
}
/* for(register long long len=n;len>=1;len--)
{
For(i,1,n-len+1)
if((a[i+len-1]-a[i-1])%7==0)
{
o(len);
exit(0);
}
}*/
For(i,,)
p[i]=inf;
For(i,,n)
{
p[a[i]%]=min(p[a[i]%],i);
ans=max(ans,i-p[a[i]%]);
}
o(ans);
return ;
}
05-11 13:49