B. Count Subrectangles

滴答滴答---题目链接 

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×m formed 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:

f968f525b71461d7167dddb750e21f919b72a4b6.pnguploading.4e448015.gif转存失败重新上传取消

There are 44 subrectangles of size 22 consisting of only ones in it:

In second example matrix cc is:

3109dd0bc266b26bdd9a8a0f1f6c5f6f8cd64093.pnguploading.4e448015.gif转存失败重新上传取消

#include<bits/stdc++.h>
using namespace std;
const int maxn=240110;
typedef long long ll;
int main()
{
   ll a[maxn];
    ll b[maxn];
    ll n,m,k;
    cin>>n>>m>>k;
    for(ll i=1; i<=n; i++)
    {
        cin>>a[i];
    }
    for(ll i=1; i<=m; i++)
    {
        cin>>b[i];
    }
    for(ll i=1; i<=n; i++)
    {
        if(a[i])
            a[i]+=a[i-1];
    }
    for(ll i=1; i<=m; i++)
    {
        if(b[i])
            b[i]+=b[i-1];
    }
    ll sum=0;
    ll t1,t2;
    for(ll i=1; i<=n; i++)
    {
        if(k%i==0)
        {
            ll p1=i;
            ll p2=k/i;
            t1=0;
            t2=0;
            for(ll j=1; j<=n; j++)
                if(a[j]>=p1)
                    t1++;
            for(ll j=1; j<=m; j++)
                if(b[j]>=p2)
                    t2++;

        sum+=t1*t2;}
    }
    printf("%lld\n",sum);
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值