skaram

Untitled

Dec 21st, 2024
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.80 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. //#pragma GCC optimize("Ofast,unroll-loops")
  4. //#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
  5.  
  6. #ifndef Local
  7. #define debug(...) 1337
  8. #define endl '\n'
  9. #endif
  10.  
  11. using namespace std;
  12.  
  13. //#define int long long
  14.  
  15. typedef long long ll;
  16. typedef long double ld;
  17.  
  18. #define all(x) (x).begin(), (x).end()
  19. #define sz(x) (int)(x).size()
  20.  
  21. template<class A, class B>
  22. bool smin(A &x, B &&y) {
  23.         if (x > y) {
  24.                 x = y;
  25.                 return true;
  26.         }
  27.         return false;
  28. }
  29.  
  30. template<class A, class B>
  31. bool smax(A &x, B &&y) {
  32.         if (x < y) {
  33.                 x = y;
  34.                 return true;
  35.         }
  36.         return false;
  37. }
  38.  
  39. const int maxn = 2000;
  40. int a[maxn][maxn];
  41. int p[maxn];
  42.  
  43. int n, m, k;
  44. char c;
  45. int i, j;
  46.  
  47. signed main() {
  48.         ios::sync_with_stdio(false), cin.tie(nullptr);
  49.  
  50.         cin >> n >> m;
  51.         for (i = 0; i < n; ++i) {
  52.                 for (j = 0; j < m; ++j) {
  53.                         a[i][j] = i * m + j;
  54.                 }
  55.         }
  56.         cin >> k;
  57.         iota(p, p + m, 0);
  58.         for (int t = 0, x_1, y_1, x_2, y_2; t < k; ++t) {
  59.                 cin >> c >> x_1 >> y_1 >> x_2 >> y_2;
  60.                 --x_1, --y_1, --x_2, --y_2;
  61.                 if (c == 'V') {
  62.                         if (y_2 - y_1 < m / 2) {
  63.                                 for (i = 0; i < (x_2 - x_1 + 1) / 2; ++i) {
  64.                                         for (j = y_1; j <= y_2; ++j) {
  65.                                                 swap(a[x_1 + i][p[j]], a[x_2 - i][p[j]]);
  66.                                         }
  67.                                 }
  68.                         } else {
  69.                                 for (i = 0; i < (x_2 - x_1 + 1) / 2; ++i) {
  70.                                         swap(a[x_1 + i], a[x_2 - i]);
  71.                                         for (j = 0; j < y_1; ++j) {
  72.                                                 swap(a[x_1 + i][p[j]], a[x_2 - i][p[j]]);
  73.                                         }
  74.                                         for (j = y_2 + 1; j < m; ++j) {
  75.                                                 swap(a[x_1 + i][p[j]], a[x_2 - i][p[j]]);
  76.                                         }
  77.                                 }
  78.                         }
  79.                 } else {
  80.                         if (x_2 - x_1 < n / 2) {
  81.                                 for (j = 0; j < (y_2 - y_1 + 1) / 2; ++j) {
  82.                                         for (i = x_1; i <= x_2; ++i) {
  83.                                                 swap(a[i][p[y_1 + j]], a[i][p[y_2 - j]]);
  84.                                         }
  85.                                 }
  86.                         } else {
  87.                                 for (j = 0; j < (y_2 - y_1 + 1) / 2; ++j) {
  88.                                         swap(p[y_1 + j], p[y_2 - j]);
  89.                                         for (i = 0; i < x_1; ++i) {
  90.                                                 swap(a[i][p[y_1 + j]], a[i][p[y_2 - j]]);
  91.                                         }
  92.                                         for (i = x_2 + 1; i < n; ++i) {
  93.                                                 swap(a[i][p[y_1 + j]], a[i][p[y_2 - j]]);
  94.                                         }
  95.                                 }
  96.                         }
  97.                 }
  98.         }
  99.         for (i = 0; i < n; ++i) {
  100.                 long long cur = 0;
  101.                 for (j = 0; j < m; ++j) {
  102.                         cur += a[i][p[j]];
  103.                 }
  104.                 cout << cur << ' ';
  105.         }
  106.         cout << endl;
  107.         for (j = 0; j < m; ++j) {
  108.                 long long cur = 0;
  109.                 for (i = 0; i < n; ++i) {
  110.                         cur += a[i][p[j]];
  111.                 }
  112.                 cout << cur << ' ';
  113.         }
  114.  
  115.         return 0;
  116. }
  117.  
Advertisement
Add Comment
Please, Sign In to add comment