skaram

Untitled

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