Advertisement
STANAANDREY

smen mars 2d

Sep 26th, 2019
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int q, x, y, x2, y2, z, smen[103][103], v[103][103], m;
  6.  
  7. int main()
  8. {
  9.  
  10.     int n;
  11.     cout << "n=";
  12.     cin >> n;
  13.     cout << "m=";
  14.     cin >> m;
  15.     cout << "v:";
  16.     for (int i = 1; i <= n; i++)
  17.         for (int j = 1; j <= m; j++)
  18.             cin >> v[i][j];
  19.     cout << "q=";
  20.     cin >> q;
  21.     while (q--)
  22.     {
  23.         cin >> x >> y >> x2 >> y2 >> z;
  24.         smen[x][y] += z;
  25.         smen[x][y2 + 1] -= z;
  26.         smen[x2 + 1][y] -= z;
  27.         smen[x2 + 1][y2 + 1] += z;
  28.     }
  29.  
  30.     for (int i = 1; i <= n; ++i)
  31.         for (int j = 1; j <= m; j++)
  32.  
  33.         {
  34.             smen[i][j] += smen[i - 1][j] + smen[i][j - 1] - smen[i - 1][j - 1];
  35.         }
  36.  
  37.     for (int i = 1; i <= n; i++)
  38.         for (int j = 1; j <= m; j++)
  39.         {
  40.             v[i][j] += smen[i][j];
  41.         }
  42.     cout << "after smen:" << endl;
  43.     for (int i = 1; i <= n; i++)
  44.     {
  45.         for (int j = 1; j <=m; j++)
  46.             cout << v[i][j] << ' ';
  47.         cout << endl;
  48.     }
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement