首先统计对以任意一个位置结尾的子数组的长,在suma和sumb数组中记录下,即suma[i]为a数组中以该点结尾的子数组长度为i的点的数量,然后计算后缀和就是长度为该值的子数组的数。
19:32过了,呜呜呜
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int const N = 40010;
int n,m,k;
int a[N],b[N];
int suma[N],sumb[N];
int main()
{
scanf("%d%d%d", &n, &m,&k);
for (int i = 0; i < n; i ++ ) scanf("%d", &a[i]);
for (int i = 0; i < m; i ++ ) scanf("%d", &b[i]);
int sa = a[0];
memset(suma, 0, sizeof suma);
for (int j = 1; j <= sa; j ++ ) suma[j]++;
for (int i = 1; i < n; i ++ ){
if(a[i]==0){
sa = 0;
}else{
sa++;
suma[sa]++;
}
}
for (int j = n-1; j >=1; j -- ) suma[j] += suma[j+1];
int sb = b[0];
memset(sumb,0, sizeof sumb);
for (int j = 1; j <= sb; j ++ ) sumb[j]++;
for (int i = 1; i < m; i ++ ){
if(b[i]==0){
sb = 0;
}else{
sb++;
sumb[sb]++;
}
}
for (int j = m-1; j >=1; j -- ) sumb[j]+=sumb[j+1];
// for (int i = 1; i <= n; i ++ ) cout<<suma[i]<<" ";
// cout<<endl;
// for (int i = 1; i <= m; i ++ ) cout<<sumb[i]<<" ";
// cout<<endl;
long long res=0;
for (int i = 1; i <= k/i; i ++ ){
int t = k/i;
if(k%i==0){
if(t<=n && i<=m)
res += suma[t] * sumb[i];
if(t<=m && i<=n && t!=i)
res += suma[i] * sumb[t];
//cout<<i<<endl;
}
}
cout<<res<<endl;
return 0;
}