fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  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. /// Sub grids
  15. void solve(){
  16. int w,h,n;
  17. cin >> w >> h >> n;
  18.  
  19. vector<vector<int>> board(w+2, vector<int>(h+2,0));
  20.  
  21. while(n--){
  22. int x1,y1;
  23. cin >> x1 >> y1;
  24.  
  25. int x2,y2;
  26. cin >> x2 >> y2;
  27.  
  28. int val1 = min(x1,x2); //x1
  29. int val2 = min(y1,y2); //y1
  30. int val3 = max(x1,x2); //x2
  31. int val4 = max(y1,y2); //y2
  32.  
  33. board[val1][val2] += 1;
  34. board[val1][val4+1] -= 1;
  35. board[val3+1][val2] -= 1;
  36. board[val3+1][val4+1] += 1;
  37. }
  38.  
  39. for(int i = 1; i <= w; i++){
  40. for(int j = 1; j <= h; j++){
  41. board[i][j] += board[i][j-1];
  42. }
  43. }
  44.  
  45. for(int i = 1; i <= w; i++){
  46. for(int j = 1; j <= h; j++){
  47. board[i][j] += board[i-1][j];
  48. }
  49. }
  50.  
  51. int ans = 0;
  52.  
  53. for(int i = 1; i <= w; i++){
  54. for(int j = 1; j <= h; j++){
  55. if(board[i][j] == 0){
  56. ans++;
  57. }
  58. }
  59. }
  60.  
  61. cout << ans << '\n';
  62. }
  63.  
  64. signed main(){
  65. FastIO();
  66.  
  67. int t;
  68. cin >> t;
  69.  
  70. while(t--){
  71. solve();
  72. }
  73. return 0;
  74. }
Success #stdin #stdout 0.01s 5272KB
stdin
3
1 1 1
1 1 1 1
2 2 2
1 1 1 2
1 1 2 1
493 182 3
349 148 363 146
241 123 443 147
303 124 293 17
stdout
0
1
83470