传送门:https://codeforces.com/contest/1323/problem/B
这是一道模拟题,需要找出来非零段的长度统计再合并之后再算一下数据就行。
题目:
ac代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<map>
#include<unordered_map>
using namespace std;
typedef long long int LL ;
typedef pair<LL,LL> PLL ;
const int N = 4e4 + 10;
LL a[N] , b[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
LL n , m , k ;
cin >> n >> m >> k ;
map<LL,LL> mplen , mplenb;
int temp = 0 ;
for(int i = 1; i <= n ; i ++)
{
cin >> a[i];
if(a[i] == 1)temp ++ ;
else if(a[i] == 0)
{
if(temp)mplen[temp] ++ ;
temp = 0 ;
}
if(i == n && temp)mplen[temp] ++ ;
}
map <PLL,int> mpsta;//大小.
temp = 0 ;
for(int i = 1; i <= m ; i ++)
{
cin >> b[i];
if(b[i] == 1)temp ++ ;
else if(b[i] == 0)
{
if(temp)mplenb[temp] ++ ;
temp = 0 ;
}
if(i == m && temp )mplenb[temp] ++ ;
}
for(auto ita : mplen)
for(auto itb : mplenb)
{
mpsta[{max(ita.first,itb.first), min(ita.first,itb.first)}] += ita.second * itb.second;
}
vector<pair<PLL,int>> v;
for(auto it : mpsta)
{
v.push_back(it);
}
LL ans = 0 ;
LL tempA,tempB;
vector<PLL> yue;
for(int i = 1; i <= k/i ; i ++)
{
if(k % i != 0)continue;
else yue.push_back({i,k/i});
}
for(int i = 0 ; i < v.size() ; i ++)
{
LL A = v[i].first.first , B = v[i].first.second;
if(A * B <k )continue;
LL tempans = 0 ;
for(int j = 0; j < yue.size(); j ++)
{
tempA = yue[j].first , tempB = yue[j].second;
if(A >= tempA && B >= tempB)
tempans += (A - tempA + 1) * (B - tempB + 1) * v[i].second;
if(tempA != tempB && A >= tempB && B >= tempA)
tempans += (A - tempB + 1) * (B - tempA + 1) * v[i].second;
}
ans += tempans;
}
cout << ans <<endl;
}