CF1323B.Count Subrectangles

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 \times m formed by following rule: ci,j=ai⋅bjc_{i, j} = a_i \cdot b_j (i.e. aia_i multiplied by bjb_j). 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,y2x_1, x_2, y_1, y_2 (1≤x1≤x2≤n1 \le x_1 \le x_2 \le n, 1≤y1≤y2≤m1 \le y_1 \le y_2 \le m) a subrectangle c[x1…x2][y1…y2]c[x_1 \dots x_2][y_1 \dots y_2] is an intersection of the rows x1,x1+1,x1+2,…,x2x_1, x_1+1, x_1+2, \dots, x_2 and the columns y1,y1+1,y1+2,…,y2y_1, y_1+1, y_1+2, \dots, y_2.

The size (area) of a subrectangle is the total number of cells in it.

给你一个长度为 nn 的数组 aa 和一个长度为 mm 的数组 bb,其中每个元素均为 00 或 11。考虑一个大小为 n×mn \times m 的矩阵 cc,其元素按如下规则定义:ci,j=ai⋅bjc_{i, j} = a_i \cdot b_j(即 aia_i 与 bjb_j 的乘积)。显然,cc 中的元素也仅由 00 和 11 构成。

矩阵 cc 中有多少个面积(即单元格总数)恰好为 kk 且全部由 11 组成的子矩形?

子矩形是指若干连续行与若干连续列的交集。换言之,给定四个整数 x1,x2,y1,y2x_1, x_2, y_1, y_2(满足 1≤x1≤x2≤n1 \le x_1 \le x_2 \le n,1≤y1≤y2≤m1 \le y_1 \le y_2 \le m),子矩形 c[x1…x2][y1…y2]c[x_1 \dots x_2][y_1 \dots y_2] 即为行 x1,x1+1,x1+2,…,x2x_1, x_1+1, x_1+2, \dots, x_2 与列 y1,y1+1,y1+2,…,y2y_1, y_1+1, y_1+2, \dots, y_2 的交集。

子矩形的大小(面积)即为其所含单元格的总数。

输入格式

The first line contains three integers nn, mm and kk (1≤n,m≤40 000,1≤k≤n⋅m1 \leq n, m \leq 40\,000, 1 \leq k \leq n \cdot m), length of array aa, length of array bb and required size of subrectangles.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤10 \leq a_i \leq 1), elements of aa.

The third line contains mm integers b1,b2,…,bmb_1, b_2, \ldots, b_m (0≤bi≤10 \leq b_i \leq 1), elements of bb.

第一行包含三个整数 nn、mm 和 kk(1≤n,m≤40 0001 \leq n, m \leq 40\,000,1≤k≤n⋅m1 \leq k \leq n \cdot m),分别表示数组 aa 的长度、数组 bb 的长度以及子矩形所需的大小。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤10 \leq a_i \leq 1),即数组 aa 的元素。

第三行包含 mm 个整数 b1,b2,…,bmb_1, b_2, \ldots, b_m(0≤bi≤10 \leq b_i \leq 1),即数组 bb 的元素。

输出格式

Output single integer — the number of subrectangles of cc with size (area) kk consisting only of ones.

输出一个整数——即由全为 1 的元素构成、面积为 kk 的子矩形 cc 的个数。

输入输出样例

  • 输入#1

    3 3 2
    1 0 1
    1 1 1

    输出#1

    4
  • 输入#2

    3 5 4
    1 1 1
    1 1 1 1 1

    输出#2

    14

说明/提示

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:

在第一个例子中,矩阵 cc 为:

其中包含 44 个大小为 22、且仅由数字 11 构成的子矩形:

在第二个例子中,矩阵 cc 为:

输入解题思路,AI测评打分。不知道怎么写?

首页