#include "mosaic.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using vi =vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pi = pair<int, int>;
using vpi = vector<pi>;
#ifdef LOCAL
#define dout std::cout
#else
#define dout if (0) std::cout
#endif
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(x) (x).begin(), (x).end()
#define en(x) (x).end()
#define bg(x) (x).begin()
#define rev(x) reverse(all(x))
#define sz(x) int((x).size())
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define each(a, x) for (auto &a : x)
#define trace(x) for (auto &el : x) dout << el << " "
vl mosaic(vi X, vi Y, vi T, vi B, vi L, vi R) {
int Q = sz(T), n = sz(X);
vl C(Q, 0);
vvi grid(n, vi(3, 0)); grid[0].resize(n); grid[1].resize(n); grid[2].resize(n);
FOR(i, 0, n) {
grid[0][i] = X[i];
grid[i][0] = Y[i];
}
map<pi, int> coord;
map<int, pi> revcoord;
int cc = 0;
for (int i = n - 1; i >= 3; i--) {
coord[{i, 2}] = cc++;
revcoord[cc-1] = {i, 2};
}
for (int i = 2; i < n; i++) {
coord[{2, i}] = cc++;
revcoord[cc-1] = {2, i};
}
FOR(i, 1, n) {
int top = i <= 2 ? n : 3;
FOR(j, 1, top) {
if (grid[i-1][j] == 0 && grid[i][j-1] == 0) grid[i][j] = 1;
else grid[i][j] = 0;
}
}
vl pref(cc+1, 0);
FOR(i, 0, cc) pref[i+1] = pref[i] + grid[revcoord[i].first][revcoord[i].second];
// FOR(i, 0, n) {
// trace(grid[i]); dout << "\n";
// }
// FOR(i, 2, n) {
// dout << grid[2][i] << " ";
// }
// dout << "\n";
// FOR(i, 3, n) {
// dout << grid[i][2] << "\n";
// }
// dout << "\n";
// FOR(i, 0, cc) dout << grid[revcoord[i].first][revcoord[i].second] << " "; dout << "\n";
// trace(pref);
// dout << "\n\n";
vvl prefix(n+1, vl(4, 0)); prefix[0].resize(n+1); prefix[1].resize(n+1); prefix[2].resize(n+1); prefix[3].resize(n+1);
FOR(i, 0, n) {
int top = i < 3 ? n : 3;
FOR(j, 0, top) {
prefix[i+1][j+1] = grid[i][j] + prefix[i+1][j];
}
// FOR(j, 0, top) {
// prefix[i+1][j+1] += prefix[i][j+1];
// }
// trace(prefix[i+1]); dout << "\n";
}
FOR(qn, 0, Q) {
int x1 = T[qn], x2 = B[qn], y1 = L[qn], y2 = R[qn];
// trace(prefix[x1+1]); dout << "\n";
if (x2 <= 2) {
C[qn] = prefix[x1+1][y2+1] - prefix[x1+1][y1];
} else {
if (y1 <= 2) {
C[qn] += prefix[x1+1][min(y2, 2) + 1] - prefix[x1+1][y1];
y1 = 3;
}
if (y1 > y2) continue;
int lx = x1 - min(x1 - 2, y1 - 2), ly = y1 - min(x1 - 2, y1 - 2);
int rx = x1 - min(x1 - 2, y2 - 2), ry = y2 - min(x1 - 2, y2 - 2);
int lc = coord[{lx, ly}], rc = coord[{rx, ry}];
// dout << "lower line: " << lc << " upper line: " << rc << "\n";
C[qn] += pref[rc+1] - pref[lc];
}
// C[qn] += pref[x2+1][y2+1];
// C[qn] += pref[x1][y1];
// C[qn] -= pref[x1][y2+1];
// C[qn] -= pref[x2+1][y1];
// if (x2 == 0 || y2 == 0) continue;
// if (x1 == 0) x1 = 1;
// if (y1 == 0) y1 = 1;
// ll width = y2 - y1 + 1;
// ll height = x2 - x1 + 1;
// if (width % 2 == 0) {
// C[qn] = width / 2 * height;
// } else if (height % 2 == 0) {
// C[qn] = height / 2 * width;
// } else {
// int maj = height / 2, min = height / 2;
// if (x1 % 2 == y1 % 2) maj++;
// else min++;
// C[qn] = ((width + 1) / 2) * maj + ((width) / 2) * min;
// }
}
return C;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |