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