This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#ifndef LOCAL
#include "mosaic.h"
#endif
using namespace std;
int cal(int x, int y) { return (x | y) ^ 1; };
vector<long long> mosaic(vector<int> X, vector<int> Y,
vector<int> T, vector<int> B,
vector<int> L, vector<int> R) {
int n = X.size();
int q = (int)T.size();
vector<long long> C(q, 0);
vector<vector<int>> a(n, vector<int>(n)), d = a;
for (int i = 0; i < n; ++i) {
a[0][i] = X[i];
a[i][0] = Y[i];
}
for (int i = 1; i < n; ++i) {
for (int j = 1; j < n; ++j) a[i][j] = cal(a[i - 1][j], a[i][j - 1]);
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
d[i][j] = a[i][j];
if (i) d[i][j] += d[i - 1][j];
if (j) d[i][j] += d[i][j - 1];
if (i && j) d[i][j] -= d[i - 1][j - 1];
}
}
for (int i = 0; i < q; ++i) {
int t = T[i], b = B[i], l = L[i], r = R[i];
int ret = d[b][r];
if (t) ret -= d[t - 1][r];
if (l) ret -= d[b][l - 1];
if (t && l) ret += d[t - 1][l - 1];
C[i] = ret;
}
return C;
}
#ifdef LOCAL
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
int N;
assert(1 == scanf("%d", &N));
std::vector<int> X(N), Y(N);
for (int i = 0; i < N; i++)
assert(1 == scanf("%d", &X[i]));
for (int i = 0; i < N; i++)
assert(1 == scanf("%d", &Y[i]));
int Q;
assert(1 == scanf("%d", &Q));
std::vector<int> T(Q), B(Q), L(Q), R(Q);
for (int k = 0; k < Q; k++)
assert(4 == scanf("%d%d%d%d", &T[k], &B[k], &L[k], &R[k]));
fclose(stdin);
std::vector<long long> C = mosaic(X, Y, T, B, L, R);
int S = (int)C.size();
for (int k = 0; k < S; k++)
printf("%lld\n", C[k]);
fclose(stdout);
return 0;
}
#endif
# | 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... |