fork download
  1. /***> @author : a_e_kasem <***/
  2. // ﷽
  3. // { وَأَنْ لَيْسَ لِلْإِنْسَانِ إِلَّا مَا سَعَى }
  4. //
  5. // فَالجُهدُ يُثمِرُ إنْ تَضافَرَ صَفوُهُ، والعَزمُ يَرفعُ صَرحَ كُلِّ بُنيانِ
  6. //
  7. // وَما نَيلُ المَطالِبِ بِالتَمَنّي
  8. // وَلَكِن تُؤخَذُ الدُنيا غِلابا
  9. // ***
  10. // وَما اِستَعصى عَلى قَومٍ مَنالٌ
  11. // إِذا الإِقدامُ كانَ لَهُم رِكابا
  12. //
  13. #include <bits/stdc++.h>
  14. using namespace std;
  15.  
  16. #define int long long
  17. #define cinAll(a) for (auto &it : a) cin >> it
  18. #define cinAll_2D(a, n, m) for(int i = 1; i <= (n); i++) for(int j = 1; j <= (m); j++) cin >> a[i][j];
  19. #define all(x) (x).begin(), (x).end()
  20. #define NO cout << "NO\n"
  21. #define YES cout << "YES\n"
  22.  
  23.  
  24.  
  25.  
  26. void solve() {
  27. int n, m; cin >> n >> m;
  28. vector<vector<int>> a(n + 1, vector<int>(m + 1));
  29. cinAll_2D(a, n, m);
  30.  
  31.  
  32. vector<vector<int>> temp(n + 2, vector<int>(m + 2));
  33. auto query = [&](int l, int r, int u, int d, int x)
  34. {
  35. temp[u][l] += x;
  36. temp[u][r + 1] -= x;
  37. temp[d + 1][l] -= x;
  38. temp[d + 1][r + 1] += x;
  39. };
  40.  
  41.  
  42. int q; cin >> q;
  43. while(q--) {
  44. int l, r, u, d, x; cin >> l >> r >> u >> d >> x;
  45. query(l, r, u, d, x);
  46. }
  47.  
  48. for(int i = 1; i <= n; i++) {
  49. for(int j = 1; j <= m; j++) {
  50. temp[i][j] += temp[i-1][j] + temp[i][j-1] - temp[i-1][j-1];
  51. a[i][j] += temp[i][j];
  52. }
  53. }
  54.  
  55. for(int i = 1; i <= n; i++) {
  56. for(int j = 1; j <= m; j++) {
  57. cout << a[i][j] << " ";
  58. }
  59. cout << "\n";
  60. }
  61. }
  62.  
  63.  
  64.  
  65.  
  66. void FastIO();
  67. int32_t main() {
  68. FastIO();
  69.  
  70. int t = 1;
  71. // cin >> t;
  72. while(t--)
  73. {
  74. solve();
  75. }
  76. }
  77.  
  78. void FastIO()
  79. {
  80. ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  81. #ifndef ONLINE_JUDGE
  82. freopen("input.txt", "r", stdin);
  83. #endif
  84. }
  85.  
  86.  
  87.  
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
Standard output is empty