CodeForces 701B Cells Not Under Attack
统计一下有多少行多少列被占领了。
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<map> #include<set> #include<queue> #include<stack> #include<iostream> using namespace std; typedef long long LL; const double pi=acos(-1.0),eps=1e-8; void File() { freopen("D:\\in.txt","r",stdin); freopen("D:\\out.txt","w",stdout); } template <class T> inline void read(T &x) { char c = getchar(); x = 0;while(!isdigit(c)) c = getchar(); while(isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); } } const int maxn=100010; int n,m,r[maxn],c[maxn]; LL sumr,sumc; int main() { scanf("%d%d",&n,&m); LL ans=(LL)n*(LL)n; for(int i=1;i<=m;i++) { int x,y; scanf("%d%d",&x,&y); if(r[x]==0) r[x]=1,sumr++; if(c[y]==0) c[y]=1,sumc++; printf("%lld ",ans-(LL)n*(sumr+sumc)+sumr*sumc); } return 0; }