没想到有生之年会写div2的B题题解,今天c比b过的多。
题意:给你两个行矩阵,4e4,全为01的,构造矩阵c,cij=ai*aj 然后输入一个面积k,问面积为k的全一矩阵有多少个,其实这个题不是何难,就是模拟起来有点麻烦,我们把所有可能的宽存起来,宽度为i的出现的次数存起来,然后加和就可以了。
也是给自己提个醒吧,做题的时候思路清晰太关键了,就咋那么一点
当时傻乎乎的写的是0,然后可能会出负值,但一直没看出来。
B. Count Subrectangles
time limit per test
1 second
memory limit per test
512 megabytes
input
standard input
output
standard output
You are given an array aa of length nn and array bb of length mm both consisting of only integers 00 and 11. Consider a matrix cc of size n×mn×mformed by following rule: ci,j=ai⋅bjci,j=ai⋅bj (i.e. aiai multiplied by bjbj). It's easy to see that cc consists of only zeroes and ones too.
How many subrectangles of size (area) kk consisting only of ones are there in cc?
A subrectangle is an intersection of a consecutive (subsequent) segment of rows and a consecutive (subsequent) segment of columns. I.e. consider four integers x1,x2,y1,y2x1,x2,y1,y2 (1≤x1≤x2≤n1≤x1≤x2≤n, 1≤y1≤y2≤m1≤y1≤y2≤m) a subrectangle c[x1…x2][y1…y2]c[x1…x2][y1…y2] is an intersection of the rows x1,x1+1,x1+2,…,x2x1,x1+1,x1+2,…,x2 and the columns y1,y1+1,y1+2,…,y2y1,y1+1,y1+2,…,y2.
The size (area) of a subrectangle is the total number of cells in it.
Input
The first line contains three integers nn, mm and kk (1≤n,m≤40000,1≤k≤n⋅m1≤n,m≤40000,1≤k≤n⋅m), length of array aa, length of array bb and required size of subrectangles.
The second line contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤10≤ai≤1), elements of aa.
The third line contains mm integers b1,b2,…,bmb1,b2,…,bm (0≤bi≤10≤bi≤1), elements of bb.
Output
Output single integer — the number of subrectangles of cc with size (area) kk consisting only of ones.
Examples
input
Copy
3 3 2 1 0 1 1 1 1
output
Copy
4
input
Copy
3 5 4 1 1 1 1 1 1 1 1
output
Copy
14
Note
In first example matrix cc is:
There are 44 subrectangles of size 22 consisting of only ones in it:
In second example matrix cc is:
#include<bits/stdc++.h>
using namespace std;
const int maxx=1e6+2;
#define ll unsigned long long
ll mod;
inline ll read(){ ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}
ll qpow(ll a,ll b){ll ans=1;while(b){if(b&1) ans=ans*a%mod;a=a*a%mod;b>>=1;}return ans; }
ll jiecheng[maxx];
ll cnm(ll n,ll m){ ll ans=qpow(jiecheng[n-m],mod-2)*qpow(jiecheng[m],mod-2)%mod; return ans*jiecheng[n]%mod;}
set<ll>st;
ll n;
vector<ll>v[maxx];
ll a[maxx],b[maxx];
char s[maxx];
ll keyi[maxx];
ll geshu[maxx];
int main()
{
ll i,t,l,r,m,j,k;
ll x,y;
//ll a,b,c,d;
ll sum=0;
n=read();
m=read();
k=read();
for(i=1;i<=n;i++) cin>>a[i];
for(j=1;j<=m;j++) cin>>b[j];
ll cnt=0;
for(i=1;i*i<=k;i++)
{
if(k%i==0)
{
keyi[++cnt]=i;
if(k!=i*i)
{
keyi[++cnt]=k/i;
}
}
}
sort(keyi+1,keyi+1+cnt);
for(i=1;i<=cnt;i++)
{
ll p=keyi[i];
//geshu[p]=0;
ll ans=0;
for(j=1;j<=n;j++)
{
if(a[j]==1)
{
ans++;
}
else
{
if(ans>=p)
{
geshu[p]+=ans-p+1;
}
ans=0;
}
}
if(ans>=p)
{
geshu[p]=geshu[p]+ans-p+1;
}
}
for(i=1;i<=cnt;i++)
{
// printf("%lld %lld\n",keyi[i],geshu[keyi[i]]);
}
sum=0;
for(i=1;i<=cnt;i++)
{
ll kuan=keyi[i];
// kuan
ll chang=k/kuan;
if(chang<=m&&kuan<=n&&geshu[kuan]>0)
{
ll ans=0;
ll zhongshu=0;
for(j=1;j<=m;j++)
{
if(b[j]==1)
{
ans++;
}
else
{
if(ans>=chang)
{
zhongshu=zhongshu+(ans-chang+1);
}
ans=0;
}
}
if(ans>=chang)
{
zhongshu=zhongshu+(ans-chang+1);
ans=0;
}
if(zhongshu>0)
sum=sum+zhongshu*geshu[kuan];
}
// printf("%lld\n",sum);
}
ll pp=0;
printf("%llu\n",max(pp,sum));
return 0;
}