题目传送门
解题思路:
二维差分的板子题.题解传送门
AC代码:
1 #include<iostream> 2 #include<cstdio> 3 4 using namespace std; 5 6 int n,k,cf[1004][1004],ans,a[1004][1004]; 7 8 int main() { 9 scanf("%d%d",&n,&k); 10 for(int i = 1;i <= n; i++) { 11 int x,y,xx,yy; 12 scanf("%d%d%d%d",&x,&y,&xx,&yy); 13 cf[x][y]++; 14 cf[xx][y]--; 15 cf[x][yy]--; 16 cf[xx][yy]++; 17 } 18 for(int i = 0;i <= 1001; i++) 19 for(int j = 0;j <= 1001; j++) { 20 a[i][j] = a[i-1][j] + a[i][j-1] - a[i-1][j-1] + cf[i][j]; 21 if(a[i][j] == k) ans++; 22 } 23 printf("%d",ans); 24 return 0; 25 }