fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. //fastio
  4. #define fastio ios::sync_with_stdio(false); cin.tie(nullptr);
  5. //iosystem,debug
  6. #ifndef ONLINE_JUDGE
  7. #define debug(x) cerr << #x << " = " << x << endl;
  8. #define iosystem freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);
  9. #else
  10. #define debug(x)
  11. #define iosystem
  12. #endif
  13.  
  14. // #define end "\n"
  15. const char nl = '\n';
  16. const char* yes="YES\n";
  17. const char* no="NO\n";
  18.  
  19. int main() {
  20. fastio;
  21. //iosystem;
  22. int T=1;
  23. cin >> T;//needed? <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  24.  
  25. while (T--) {
  26.  
  27.  
  28.  
  29. int w,h,n;
  30. cin>>w>>h>>n;
  31. vector<vector<int>>grid(h+1,vector<int>(w+1,0));
  32.  
  33. //input and ((( partial ))) sum >>>is written right????review it
  34. int x1,y1,x2,y2;
  35. for (int i = 0 ; i < n; i++) {
  36. cin>>x1>>y1>>x2>>y2;
  37.  
  38. if(x1>x2) swap(x1,x2);
  39. if(y1>y2) swap(y1,y2);
  40.  
  41. x1--,y1--,x2--,y2--;//0-indexed
  42. grid[y1][x1]++;
  43.  
  44. grid[y1][x2+1]--;
  45. grid[y2+1][x1]--;
  46.  
  47. grid[y2+1][x2+1]++;
  48.  
  49. }
  50.  
  51. //prefix sum part
  52. for (int i = 0 ; i < h ; i++) {
  53. for ( int j = 1 ; j < w ; j++) {
  54. grid[i][j]+=grid[i][j-1];
  55. }
  56. }
  57. for (int i = 1 ; i < h ; i++) {
  58. for ( int j = 0 ; j < w ; j++) {
  59. grid[i][j]+=grid[i-1][j];
  60. }
  61. }
  62.  
  63. //counting
  64. int cnt=0;
  65. for(int i = 0 ; i< h; i++){
  66. for(int j = 0 ; j < w ;j++){
  67. if(!grid[i][j]) cnt++;
  68. }
  69. }
  70.  
  71. //answer
  72. cout<<cnt<<nl;
  73.  
  74.  
  75. //wrong
  76. // int res=0;
  77. // for (int i = 0 ;i < h; i++) {
  78. // for (int j = 0 ; j < w ; j ++) {
  79. // if (grid[h-1][w-1]) res++;
  80. // }
  81. // }
  82. // cout<<res<<nl;
  83.  
  84.  
  85.  
  86. }
  87.  
  88.  
  89.  
  90. }
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
Success #stdin #stdout 0.01s 5264KB
stdin
Standard input is empty
stdout
21974