Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma GCC optimize("Ofast")
- #include <bits/stdc++.h>
- //#pragma GCC optimize("Ofast,unroll-loops")
- //#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
- #ifndef Local
- #define debug(...) 1337
- #define endl '\n'
- #endif
- using namespace std;
- //#define int long long
- typedef long long ll;
- typedef long double ld;
- #define all(x) (x).begin(), (x).end()
- #define sz(x) (int)(x).size()
- template<class A, class B>
- bool smin(A &x, B &&y) {
- if (x > y) {
- x = y;
- return true;
- }
- return false;
- }
- template<class A, class B>
- bool smax(A &x, B &&y) {
- if (x < y) {
- x = y;
- return true;
- }
- return false;
- }
- constexpr int maxn = 2000;
- vector<int> a[maxn];
- int p[maxn];
- int n, m, k;
- char c;
- int i, j;
- int t, x_1, y_1, x_2, y_2;
- int d;
- #define MAGIC 0
- signed main() {
- ios::sync_with_stdio(false), cin.tie(nullptr);
- cin >> n >> m;
- for (i = 0; i < n; ++i) {
- a[i].resize(m);
- for (j = 0; j < m; ++j) {
- a[i][j] = i * m + j;
- }
- }
- cin >> k;
- iota(p, p + m, 0);
- for (t = 0; t < k; ++t) {
- cin >> c >> x_1 >> y_1 >> x_2 >> y_2;
- --x_1, --y_1, --x_2, --y_2;
- if (c == 'V') {
- if (y_2 - y_1 < m / 2 + MAGIC) {
- d = (x_2 - x_1 + 1) / 2;
- for (i = 0; i < d; ++i) {
- for (j = y_1; j <= y_2; ++j) {
- swap(a[x_1 + i][p[j]], a[x_2 - i][p[j]]);
- }
- }
- } else {
- d = (x_2 - x_1 + 1) / 2;
- for (i = 0; i < d; ++i) {
- swap(a[x_1 + i], a[x_2 - i]);
- for (j = 0; j < y_1; ++j) {
- swap(a[x_1 + i][p[j]], a[x_2 - i][p[j]]);
- }
- for (j = y_2 + 1; j < m; ++j) {
- swap(a[x_1 + i][p[j]], a[x_2 - i][p[j]]);
- }
- }
- }
- } else {
- if (x_2 - x_1 < n / 2 + MAGIC) {
- d = (y_2 - y_1 + 1) / 2;
- for (j = 0; j < d; ++j) {
- for (i = x_1; i <= x_2; ++i) {
- swap(a[i][p[y_1 + j]], a[i][p[y_2 - j]]);
- }
- }
- } else {
- d = (y_2 - y_1 + 1) / 2;
- for (j = 0; j < d; ++j) {
- swap(p[y_1 + j], p[y_2 - j]);
- for (i = 0; i < x_1; ++i) {
- swap(a[i][p[y_1 + j]], a[i][p[y_2 - j]]);
- }
- for (i = x_2 + 1; i < n; ++i) {
- swap(a[i][p[y_1 + j]], a[i][p[y_2 - j]]);
- }
- }
- }
- }
- }
- for (i = 0; i < n; ++i) {
- long long cur = 0;
- for (j = 0; j < m; ++j) {
- cur += a[i][p[j]];
- }
- cout << cur << ' ';
- }
- cout << endl;
- for (j = 0; j < m; ++j) {
- long long cur = 0;
- for (i = 0; i < n; ++i) {
- cur += a[i][p[j]];
- }
- cout << cur << ' ';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment