Guest User

Untitled

a guest
Dec 3rd, 2020
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.02 KB | None | 0 0
  1. //#pragma comment(linker, "/stack:200000000")
  2. #pragma GCC optimize("O3", "Ofast", "fast-math")
  3.  
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. using ll = long long;
  9. using ld = long double;
  10. using ull = unsigned long long;
  11.  
  12. #define all(v) v.begin(), v.end()
  13. #define rall(v) v.rbegin(), v.rend()
  14. #define F first
  15. #define S second
  16. // #define int ll
  17. // #define double long double
  18. // #define size_t int
  19.  
  20. int a[2048][2000];
  21.  
  22. size_t n, m;
  23. size_t q;
  24.  
  25. signed main() {
  26.     cin.tie(0);
  27.     cout.tie(0);
  28.     ios_base::sync_with_stdio(0);
  29.     cin >> n >> m;
  30.     for (size_t i = 0; i < n; ++i) {
  31.         for (size_t j = 0; j < m; ++j) {
  32.             a[i][j] = i * m + j;
  33.         }
  34.     }
  35.     cin >> q;
  36.     while (q--) {
  37.         char c;
  38.         size_t l, r, x, y;
  39.         cin >> c >> l >> x >> r >> y;
  40.         --l, --x, --r, --y;
  41.         size_t cc;
  42.         if (c == 'H') {
  43.             for (size_t i = l; i <= r; ++i) {
  44.                 size_t rr = (max<size_t>(x + y, 1) - 1) / 2;
  45.                 for (size_t j = x; j <= rr; ++j) {
  46.                     cc = y + x - j;
  47.                     a[i][j] ^= a[i][cc];
  48.                     a[i][cc] ^= a[i][j];
  49.                     a[i][j] ^= a[i][cc];
  50.                 }
  51.             }
  52.         } else {
  53.             size_t rr = (l + r - 1) / 2;
  54.             for (size_t i = l; i <= rr; ++i) {
  55.                 for (size_t j = x; j <= y; ++j) {
  56.                     cc = r + l - i;
  57.                     a[i][j] ^= a[cc][j];
  58.                     a[cc][j] ^= a[i][j];
  59.                     a[i][j] ^= a[cc][j];
  60.                 }
  61.             }
  62.         }
  63.     }
  64.     for (size_t i = 0; i < n; ++i) {
  65.         long long s = 0;
  66.         for (size_t j = 0; j < m; ++j) {
  67.             s += a[i][j];
  68.         }
  69.         cout << s << ' ';
  70.     }
  71.     cout << '\n';
  72.     long long d[m] = {};
  73.     for (size_t i = 0; i < n; ++i) {
  74.         for (size_t j = 0; j < m; ++j) {
  75.             d[j] += a[i][j];
  76.         }
  77.     }
  78.     for (size_t i = 0; i < m; ++i) {
  79.         cout << d[i] << ' ';
  80.     }
  81.     return 0;
  82. }
Add Comment
Please, Sign In to add comment