luogu3941 into the matrix song

Source: Internet
Author: User

https://www.zybuluo.com/ysner/note/1301562 Problem surface

Statistics in the given \ (n*m\) matrix, how many different sub-rectangles are the sum of the numbers in a multiple of \ (k\) ?

Analytical

I can't cut the problem, I'm a jerk.
It is obvious that each column is preprocessed with a prefix and.
It then enumerates the upper and lower bounds of the rectangle, counting which columns in the range are equal in line.

#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>#define ll long long#define re register#define il inline#define fp(i,a,b) for(re int i=a;i<=b;i++)#define fq(i,a,b) for(re int i=a;i>=b;i--)using namespace std;const int N=500,M=1e6+100;int n,m,k,mx=1e6,tag=1,s[N][N],t[M];ll ans;il ll gi(){  re ll x=0,t=1;  re char ch=getchar();  while(ch!=‘-‘&&(ch<‘0‘||ch>‘9‘)) ch=getchar();  if(ch==‘-‘) t=-1,ch=getchar();  while(ch>=‘0‘&&ch<=‘9‘) x=x*10+ch-48,ch=getchar();  return x*t;}int main(){  n=gi();m=gi();k=gi();  fp(i,1,n)    fp(j,1,m)    s[i][j]=(gi()+s[i-1][j]+s[i][j-1]-s[i-1][j-1]+k)%k;  fp(i,1,n)    fp(j,i,n)    {      fp(l,0,m) ++t[(s[j][l]-s[i-1][l]+k)%k];      fp(l,0,m) --t[(s[j][l]-s[i-1][l]+k)%k],ans+=t[(s[j][l]-s[i-1][l]+k)%k];    }  printf("%lld\n",ans);  return 0;}

luogu3941 into the matrix song

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.