fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. inline int power(int a, int b) {
  6. int x = 1;
  7. while (b) {
  8. if (b & 1) x *= a;
  9. a *= a;
  10. b >>= 1;
  11. }
  12. return x;
  13. }
  14.  
  15.  
  16. const int M = 1000000007;
  17. const int N = 3e5+9;
  18. const int INF = 2e9+1;
  19. const int LINF = 2000000000000000001;
  20.  
  21. //_ ***************************** START Below *******************************
  22.  
  23.  
  24.  
  25.  
  26. vector<vector<int>> queries;
  27. void consistency(int n, int m) {
  28.  
  29. vector<vector<int>> dif(n, vector<int>(n, 0));
  30. for(auto& q : queries){
  31. int x = q[0];
  32. int y = q[1];
  33. int a = q[2];
  34. int b = q[3];
  35. dif[x][y]++;
  36. if(a+1<n) dif[a+1][y]--;
  37. if(b+1<n) dif[x][b+1]--;
  38. if(a+1<n && b+1<n) dif[a+1][b+1]++;
  39. }
  40. for(int i=0; i<n; i++){
  41. for(int j=0; j<n; j++){
  42. // dif[i][j] = 0 + dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1];
  43. if(i-1>=0)
  44. dif[i][j] += dif[i-1][j];
  45. if(j-1>=0)
  46. dif[i][j] += dif[i][j-1];
  47. if(i-1>=0 && j-1>=0) dif[i][j] -= dif[i-1][j-1];
  48. }
  49. }
  50.  
  51. for(int i=0; i<n; i++){
  52. for(int j=0; j<n; j++){
  53. cout << dif[i][j] << " ";
  54. }cout << endl;
  55. }
  56. }
  57.  
  58. void solve() {
  59.  
  60. int n, m;
  61. cin >> n >> m;
  62. queries.resize(m);
  63. for(int i=0; i<m; i++){
  64. int x,a, y,b;
  65. cin >> x >> a >> y >> b;
  66. queries[i] = {x,a,y,b};
  67. }
  68.  
  69. consistency(n, m);
  70.  
  71. }
  72.  
  73.  
  74.  
  75.  
  76.  
  77. int32_t main() {
  78. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  79.  
  80. int t = 1;
  81. while (t--) {
  82. solve();
  83. }
  84.  
  85. return 0;
  86. }
Success #stdin #stdout 0s 5316KB
stdin
3 2
1 1 2 2
0 0 1 1
stdout
1 1 0 
1 2 1 
0 1 1