Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <ext/pb_ds/detail/standard_policies.hpp>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- #include <immintrin.h>
- #define pb push_back
- #define F first
- #define S second
- #define ll long long
- #define ld long double
- #define pii pair <int, int>
- #define ull unsigned long long
- //#define int long long
- //#pragma comment(linker, "/stack:200000000")
- //#pragma GCC optimize("Ofast")
- //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
- #pragma GCC optimize("unroll-loops")
- #pragma GCC optimize("-O3")
- using namespace std;
- using namespace __gnu_pbds;
- template <typename T>
- using ordered_set = tree <T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
- mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());
- const int N = 2e3 + 1;
- const int M = 3e4 + 5;
- const ll mod = 1e9 + 81;
- const int rx[8] = {1, -1, 0, 0, 1, 1, -1, -1};
- const int ry[8] = {0, 0, 1, -1, 1, -1, 1, -1};
- const int kx[8] = {1, 1, -1, -1, 2, 2, -2, -2};
- const int ky[8] = {2, -2, 2, -2, 1, -1, 1, -1};
- const ld pi = acos(-1.0);
- const ld eps = 1e-9;
- int a[N][N * 5];
- #define kek __m128i
- __attribute__((target("avx"))) void KEK(int *up, int *down, int len) {
- for (int i = len - len % 8; i < len; ++i) swap(up[i], down[i]);
- kek* l = (kek*)up;
- kek* r = (kek*)down;
- for (int i = 0; i < len / 8; ++i, l += 2, r += 2) {
- kek a = _mm_loadu_si128(l);
- kek b = _mm_loadu_si128(l + 1);
- kek c = _mm_loadu_si128(r);
- kek d = _mm_loadu_si128(r + 1);
- _mm_storeu_si128((kek*)l, c);
- _mm_storeu_si128((kek*)l + 1, d);
- _mm_storeu_si128((kek*)r, a);
- _mm_storeu_si128((kek*)r + 1, b);
- }
- }
- #define FILE "e"
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- #ifdef LOCAL
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #else
- // freopen(FILE".in", "r", stdin);
- //freopen(FILE".out", "w", stdout);
- #endif // LOCAL
- int n, m;
- cin >> n >> m;
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++) {
- a[i][j] = i * m + j;
- }
- }
- int q;
- cin >> q;
- if (1ll * n * m * q < 1e8) {
- while (q--) {
- char t;
- int x1, y1, x2, y2;
- cin >> t >> x1 >> y1 >> x2 >> y2;
- x1--, y1--, x2--, y2--;
- if (t == 'V') {
- for (int j = y1; j <= y2; ++j) {
- for (int i = 0; i < (x2 - x1 + 1) >> 1; ++i) {
- swap(a[x1 + i][j], a[x2 - i][j]);
- }
- }
- } else {
- for (int i = x1; i <= x2; ++i) {
- for (int j = 0; j < (y2 - y1 + 1) >> 1; ++j) {
- swap(a[i][y1 + j], a[i][y2 - j]);
- }
- }
- }
- }
- } else {
- while (q--) {
- char t;
- int x1, y1, x2, y2;
- cin >> t >> x1 >> y1 >> x2 >> y2;
- x1--, y1--, x2--, y2--;
- if (t == 'V') {
- for (int i = 0; i < (x2 - x1 + 1) >> 1; ++i) {
- KEK(a[x1 + i] + y1, a[x2 - i] + y1, y2 - y1 + 1);
- }
- } else {
- for (int i = x1; i <= x2; ++i) {
- for (int j = 0; j < (y2 - y1 + 1) >> 1; ++j) {
- swap(a[i][y1 + j], a[i][y2 - j]);
- }
- }
- }
- }
- }
- for (int i = 0; i < n; i++) {
- ll x = 0;
- for (int j = 0; j < m; j++) {
- x += a[i][j];
- }
- cout << x << " ";
- }
- cout << "\n";
- for (int j = 0; j < m; j++) {
- ll x = 0;
- for (int i = 0; i < n; i++) {
- x += a[i][j];
- }
- cout << x << " ";
- }
- cout << "\n";
- cerr << 1.0 * clock() / CLOCKS_PER_SEC << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement