比赛 |
noi pro 模拟赛 |
评测结果 |
AAAAAAAAAA |
题目名称 |
AAAA(无题面) |
最终得分 |
100 |
用户昵称 |
胡嘉兴 |
运行时间 |
0.181 s |
代码语言 |
C++ |
内存使用 |
5.21 MiB |
提交时间 |
2018-10-26 21:40:55 |
显示代码纯文本
#include<bits/stdc++.h>
#define ll long long
#define lowbit(x) (x&-x)
using namespace std;
const int N = 5e2+7;
int n, m;
int a[N][N], f[N][N][4];
void rebuild1(int i)
{
for(int j = 1; j <= m; j++)
{
f[i][j][0] = (a[i][j]==a[i][j-1])?f[i][j-1][0]+1:1;
}
for(int j = m; j >= 1; j--)
{
f[i][j][1] = (a[i][j]==a[i][j+1])?f[i][j+1][1]+1:1;
}
return;
}
void rebuild2(int j)
{
for(int i = 1; i <= n; i++)
{
f[i][j][2] = (a[i][j]==a[i-1][j])?f[i-1][j][2]+1:1;
}
for(int i = n; i >= 1; i--)
{
f[i][j][3] = (a[i][j]==a[i+1][j])?f[i+1][j][3]+1:1;
}
return;
}
int calc1(int x, int y, int o)
{
int l = x, r = x, res = 0;
for(int i = f[x][y][o]; i >= 1; i--)
{
while(l>=1&&a[l][y]==a[x][y]&&f[l][y][o]>=i)
{
l--;
}
while(r<=n&&a[r][y]==a[x][y]&&f[r][y][o]>=i)
{
r++;
}
res = max(res, ((--r)-(++l)+1)*i);
}
return res;
}
int calc2(int x, int y, int o)
{
int l = y, r = y, res = 0;
for(int i = f[x][y][o]; i >= 1; i--)
{
while(l>=1&&a[x][l]==a[x][y]&&f[x][l][o]>=i)
{
l--;
}
while(r<=m&&a[x][r]==a[x][y]&&f[x][r][o]>=i)
{
r++;
}
res = max(res, ((--r)-(++l)+1)*i);
}
return res;
}
int main()
{
int p;
freopen("test.in", "r", stdin);
freopen("test.out", "w", stdout);
freopen("AAAA.in", "r", stdin);
freopen("AAAA.out", "w", stdout);
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
scanf("%d", &a[i][j]);
}
rebuild1(i);
}
for(int j = 1; j <= m; j++)
{
rebuild2(j);
}
scanf("%d", &p);
while(p--)
{
int x1, y1, x2, y2, ans = 0;
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
swap(a[x1][y1], a[x2][y2]);
rebuild1(x1);rebuild1(x2);
rebuild2(y1);rebuild2(y2);
if(x1==x2)
{
for(int i = 0; i < 2; i++)
{
ans = max(ans, max(calc1(x1, y1, i), calc1(x2, y2, i)));
}
}
else
{
for(int i = 2; i < 4; i++)
{
ans = max(ans, max(calc2(x1, y1, i), calc2(x2, y2, i)));
}
}
printf("%d\n", ans);
}
return 0;
}