Count Subrectangles CodeForces - 1323B(思维)
You are given an array a of length n and array b of length m both consisting of only integers 0 and 1. Consider a matrix c of size n×m formed by following rule: ci,j=ai?bj (i.e. ai multiplied by bj). It’s easy to see that c consists of only zeroes and ones too.
How many subrectangles of size (area) k consisting only of ones are there in c?
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,y2 (1≤x1≤x2≤n, 1≤y1≤y2≤m) a subrectangle c[x1…x2][y1…y2] is an intersection of the rows x1,x1+1,x1+2,…,x2 and the columns y1,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 n, m and k (1≤n,m≤40000,1≤k≤n?m), length of array a, length of array b and required size of subrectangles.
The second line contains n integers a1,a2,…,an (0≤ai≤1), elements of a.
The third line contains m integers b1,b2,…,bm (0≤bi≤1), elements of b.
Output
Output single integer — the number of subrectangles of c with size (area) k consisting only of ones.
Examples
Input
3 3 2
1 0 1
1 1 1
Output
4
Input
3 5 4
1 1 1
1 1 1 1 1
Output
14
Note
In first example matrix c is:
There are 4 subrectangles of size 2 consisting of only ones in it:
In second example matrix c is:
思路:思路感覺挺好想的,但是有可能容易超時。對于連續的1個數相同的情況,我們可以合并考慮,因為他們的情況都是一樣的。因此,我們可以分別計算出a序列,連續的1的個數有多少種情況,并記錄每一種情況的個數。同理求出b序列的。然后我們分別遍歷a,b序列的這些情況,求出符合條件的就可以了。
代碼如下:
努力加油a啊,(o)/~
總結
以上是生活随笔為你收集整理的Count Subrectangles CodeForces - 1323B(思维)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [蓝桥杯][历届试题]网络寻路(DFS)
- 下一篇: Unusual Competitions