Gym - 101991D
Gym - 101991D
离散化+前缀和统计
上次写离散化已经是一年前多了
#include <bits/stdc++.h> #define inf 2333333333333333 #define N 1010 #define p(a) putchar(a) #define For(i,a,b) for(long long i=a;i<=b;++i) using namespace std; long long T,n,m,k,lx,ly,ans; long long x[N],y[N],f[N][N]; struct node{ long long x; long long y; }a[N]; map<long long,long long>mx; map<long long,long long>my; void in(long long &x){ long long y=1;char c=getchar();x=0; while(c<'0'||c>'9'){if(c=='-')y=-1;c=getchar();} while(c<='9'&&c>='0'){ x=(x<<1)+(x<<3)+c-'0';c=getchar();} x*=y; } void o(long long x){ if(x<0){p('-');x=-x;} if(x>9)o(x/10); p(x%10+'0'); } void init(){ memset(f,0,sizeof(f)); mx.clear();my.clear(); } signed main(){ freopen("dull.in","r",stdin); in(T); while(T--){ init(); in(n);in(m);in(k); For(i,1,k){ in(x[i]);in(y[i]); a[i].x=x[i];a[i].y=y[i]; } sort(x+1,x+k+1); sort(y+1,y+k+1); lx=unique(x+1,x+k+1)-x-1; ly=unique(y+1,y+k+1)-y-1; For(i,1,lx) mx[x[i]]=i; For(i,1,ly) my[y[i]]=i; For(i,1,k) f[mx[a[i].x]][my[a[i].y]]=1; For(i,1,lx){ For(j,1,ly){ f[i][j]+=f[i-1][j]+f[i][j-1]-f[i-1][j-1]; } } x[lx+1]=n+1;y[ly+1]=m+1; ans=0; For(i,1,lx){ For(j,1,ly){ if(f[i][j]%2){ ans+=(x[i+1]-x[i])*(y[j+1]-y[j]); } } } o(ans);p(' ');o(n*m-ans);p('\n'); } return 0; }