#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second
using namespace std;
using ll = long long;
const ll N = 5005 , inf = 2e9 + 7;
const ll INF = 1e18 , mod = 1e9+7;
int dp[N][N] , pr[N][N];
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();
for(int i = 1; i <= n; i++){
dp[1][i] = X[i-1];
dp[i][1] = Y[i-1];
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(i == 1 || j == 1) continue;
if(dp[i-1][j] == 0 && dp[i][j-1] == 0) dp[i][j] = 1;
else dp[i][j] = 0;
}
}
map<ll,ll> mp;
for(int j = 2 , i = 3; j <= n; j++){
mp[i-j] |= dp[i][j];
}
for(int i = 2 , j = 3; i <= n; i++){
mp[i-j] |= dp[i][j];
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(i > 3 && j > 3){
dp[i][j] = mp[i-j];
}
pr[i][j] = dp[i][j] + pr[i-1][j] + pr[i][j-1] - pr[i-1][j-1];
}
}
int q = (int)T.size();
vector<long long> C(q, 0);
for(int i = 0; i < q; i++){
B[i]++;
R[i]++;
C[i] = pr[B[i]][R[i]] - pr[T[i]][R[i]] - pr[B[i]][L[i]] + pr[T[i]][L[i]];
}
return C;
}
// int main() {
// 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;
// }
# | 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... |