# Educational Codeforces Round 8（E. Zbazi in Zeydabad（树状数组优化））★ ★

#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define L(i) i<<1
#define R(i) i<<1|1
#define INF  0x3f3f3f3f
#define pi acos(-1.0)
#define eps 1e-9
#define maxn 3100
#define MOD 1000000007

int T,n,m, bit[maxn*2][maxn],l[maxn][maxn];
int lr[maxn][maxn],r[maxn][maxn];
long long ans = 0;
struct node
{
int x, y;
};
vector<node> g[maxn];
char s[maxn][maxn];

int sum(int i, int x)
{
int ans = 0;
while(x > 0)
{
ans += bit[i][x];
x -= x & -x;
}
return ans;
}
void add(int i, int x, int d)
{
while(x <= m)
{
bit[i][x] += d;
x += x & -x;
}
}
void pre()
{
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
if(s[i][j] == 'z')
l[i][j] = l[i][j-1] + 1;
else
l[i][j] = 0;
}
for(int j = m; j >= 1; j--)
{
if(s[i][j] == 'z')
r[i][j] = r[i][j+1] + 1;
else
r[i][j] = 0;
}
}
for(int i = n; i >= 1; i--)
{
for(int j = 1; j <= m; j++)
{
if(s[i][j] != 'z')
{
lr[i][j] = 0;
continue;
}
if(j-1 >= 1 && i+1 <= n)
lr[i][j] = lr[i+1][j-1] + 1;
else
lr[i][j] = 1;
}
}
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
g[j + r[i][j] - 1].push_back(node{i,j});
}

int main()
{
scanf("%d%d",&n,&m);
for(int i = 1; i <= n; i++)
scanf("%s",s[i]+1);
ans = 0;
pre();
for(int j = m; j >= 1; j--)
{
int len = g[j].size();
for(int i = 0; i < len; i++)
{
int x = g[j][i].x, y = g[j][i].y;
}
for(int i = 1; i <= n; i++)
{
if(s[i][j] != 'z')
continue;
int len = min(l[i][j], lr[i][j]);
ans += sum(j+i, j) - sum(i+j, j-len);
}
}
printf("%I64d\n",ans);
return 0;
}


• 本文已收录于以下专栏：

举报原因： 您举报文章：Educational Codeforces Round 8（E. Zbazi in Zeydabad（树状数组优化））★ ★ 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)