fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. #include <algorithm>
  5. #include <bits/stdc++.h>
  6. #include <set>
  7. #include <ext/pb_ds/assoc_container.hpp>
  8. #include <ext/pb_ds/tree_policy.hpp>
  9. #include <map>
  10. #define ll long long
  11. using namespace __gnu_pbds;
  12. using namespace std;
  13. template <class T>
  14. using ordered_set = tree<T , null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update>;
  15. template <class T>
  16. using ordered_set1 = tree<T , null_type , greater<T> , rb_tree_tag , tree_order_statistics_node_update>;
  17. // less<T>/greater<T> = ascending/descending.
  18. // less_equal<>/greater_equal<> for ordered multiset
  19. // ordered_multiset note : s.find(), s.erase() don't work + s.upper_bound() and s.lower_bound() swap jobs;
  20. void fastIO(void) {
  21. ios_base::sync_with_stdio(false);
  22. cin.tie(NULL);
  23. cout.tie(NULL);
  24. }
  25. int arr[1002][1002]={};
  26. int main() {
  27. fastIO();
  28. int n,k; cin>>n>>k;
  29. while (n--) {
  30. int x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2;
  31. arr[y1][x1]++;
  32. arr[y2+1][x1]--;
  33. arr[y1][x2+1]--;
  34. arr[y2+1][x2+1]++;
  35. }
  36. for (int i = 1; i<=1000; i++) {
  37. for (int j = 1; j<=1000; j++) {
  38. arr[i][j]+=arr[i-1][j];
  39. }
  40. }
  41. for (int i = 1; i<=1000; i++) {
  42. for (int j = 1; j<=1000; j++) {
  43. arr[i][j]+=arr[i][j-1];
  44. }
  45. }
  46. int count = 0;
  47. for (int i = 1; i<=1000; i++) {
  48. for (int j = 1; j<=1000; j++) {
  49. if (arr[i][j]==k) count++;
  50. }
  51. }
  52. cout<<count;
  53. }
Success #stdin #stdout 0.01s 7528KB
stdin
3 2
1 1 5 5
4 4 7 6
3 3 8 7
stdout
13