题解
行和列分别用数组表示,每放一子,标记所在行和列,同时记下” under attack “的行数和列数。
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 100000 + 10;
bool xflag[maxn], yflag[maxn];
int n, m;
int main()
{
cin >> n >> m;
LL cells = (LL)n * n;
int x, y;
int dx = 0, dy = 0;
for(int i = 0; i < m; ++i){
scanf("%d %d", &x, &y);
if(!xflag[x]){
cells -= n - dy;
xflag[x] = true;
dx++;
}
if(!yflag[y]){
cells -= n - dx;
yflag[y] = true;
dy++;
}
printf("%I64d ", cells);
}
return 0;
}