fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5. #define yes cout << "YES\n";
  6. #define no cout << "NO\n";
  7.  
  8.  
  9. void FastIO(){
  10. ios_base::sync_with_stdio(false);
  11. cin.tie(nullptr);
  12. cout.tie(nullptr);
  13. }
  14.  
  15. void solve(){
  16. int n, k;
  17. cin >> n >> k;
  18.  
  19. vector<vector<int>> grid(1005, vector<int>(1005, 0));
  20.  
  21. while(n--){
  22. int x1, y1, x2, y2;
  23. cin >> x1 >> y1 >> x2 >> y2;
  24.  
  25. grid[x1][y1] += 1;
  26. grid[x1][y2] -= 1;
  27. grid[x2][y1] -= 1;
  28. grid[x2][y2] += 1;
  29. }
  30.  
  31. for(int i = 0; i <= 1000; i++){
  32. for(int j = 1; j <= 1000; j++){
  33. grid[i][j] += grid[i][j-1];
  34. }
  35. }
  36.  
  37. for(int i = 1; i <= 1000; i++){
  38. for(int j = 0; j <= 1000; j++){
  39. grid[i][j] += grid[i-1][j];
  40. }
  41. }
  42.  
  43. int ans = 0;
  44. for(int i = 0; i < 1000; i++){
  45. for(int j = 0; j < 1000; j++){
  46. if(grid[i][j] == k)
  47. ans++;
  48. }
  49. }
  50.  
  51. cout << ans << "\n";
  52. }
  53.  
  54.  
  55. signed main(){
  56. freopen("paintbarn.in","r",stdin);
  57. freopen("paintbarn.out","w",stdout);
  58. FastIO();
  59.  
  60. int t = 1;
  61. //cin >> t;
  62.  
  63. while (t--){
  64. solve();
  65. }
  66. return 0;
  67. }
Success #stdin #stdout 0.02s 11084KB
stdin
3 2
1 1 5 5
4 4 7 6
3 3 8 7
stdout
8