#include "mosaic.h"
#define pb push_back
#include <vector>
#include<bits/stdc++.h>
using namespace std;
const int maxn = 5005;
int a[maxn][maxn], pref[maxn][maxn];
int n;
std::vector<long long> mosaic(std::vector<int> X, std::vector<int> Y,
std::vector<int> T, std::vector<int> B,
std::vector<int> L, std::vector<int> R)
{
int q = (int)T.size();
std::vector<long long> C(q, 0);
n = X.size();
for (int i = 1; i <= n; ++ i)
a[1][i] = X[i-1];
for (int i = 1; i <= n; ++ i)
pref[1][i] = pref[1][i-1] + a[1][i];
for (int i = 0; i < q; ++ i)
{
int l = L[i] + 1;
int r = R[i] + 1;
C[i] = pref[1][r] - pref[1][l-1];
}
return C;
for (int i = 1; i <= n; ++ i)
a[i][1] = Y[i-1];
for (int i = 2; i <= n; ++ i)
{
for (int j = 2; j <= n; ++ j)
{
if(!a[i-1][j] && !a[i][j-1])a[i][j] = 1;
else a[i][j] = 0;
}
}
/**for (int i = 1; i <= n; ++ i)
{
for (int j = 1; j <= n; ++ j)
cout << a[i][j] << " ";
cout << endl;
}*/
for (int i = 2; i <= n; ++ i)
pref[i][1] = pref[i-1][1] + a[i][1];
for (int i = 2; i <= n; ++ i)
{
for (int j = 2; j <= n; ++ j)
{
pref[i][j] = pref[i-1][j] + pref[i][j-1] + a[i][j] - pref[i-1][j-1];
}
}
q = (int)T.size();
//std::vector<long long> C(q, 0);
for (int i = 0; i < q; ++ i)
{
int t = T[i] + 1;
int b = B[i] + 1;
int l = L[i] + 1;
int r = R[i] + 1;
long long ans = pref[b][r] - pref[t-1][r] - pref[b][l-1] + pref[t-1][l-1];
C[i] = ans;
}
return C;
}
/**
4
1 0 1 0
1 1 0 1
2
0 3 0 3
2 3 0 2
*/
# | 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... |