日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Count Subrectangles CodeForces - 1323B(思维)

發布時間:2023/12/15 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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序列的這些情況,求出符合條件的就可以了。
代碼如下:

#include<bits/stdc++.h> #define ll long long using namespace std;const int maxx=4e4+100; map<int,int> p1,p2; int a[maxx]; int b[maxx]; int n,m,k;inline void dfs(int c[],int &j,int limit) {if(j>limit) return ;if(c[j]==0) return ;dfs(c,j+=1,limit); } inline void fcs() {int j;for(int i=1;i<=n;){if(a[i]==1){j=i;dfs(a,j,n);p1[j-i]++;i=j;}else i++;}for(int i=1;i<=m;){if(b[i]==1){j=i;dfs(b,j,m);p2[j-i]++;i=j;}else i++;} } inline void solve() {int len1,len2,num1,num2,_min,_max;ll sum=0;for(map<int,int> ::iterator it1=p1.begin();it1!=p1.end();it1++){len1=it1->first;num1=it1->second;for(map<int,int> ::iterator it2=p2.begin();it2!=p2.end();it2++){len2=it2->first;num2=it2->second;_min=min(len1,len2);_max=max(len1,len2);for(int i=1;i<=min(_min,k);i++){if(k%i==0&&k/i<=_max) sum+=((_max-k/i+1)*(_min-i+1))*num1*num2;}}}cout<<sum<<endl; } int main() {scanf("%d%d%d",&n,&m,&k);for(int i=1;i<=n;i++) cin>>a[i];for(int i=1;i<=m;i++) cin>>b[i];p1.clear();p2.clear();fcs();solve();return 0; }

努力加油a啊,(o)/~

總結

以上是生活随笔為你收集整理的Count Subrectangles CodeForces - 1323B(思维)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。