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 "rect.h"
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,bmi,bmi2")
using namespace std;
using i32 = int;
//#define int long long
#define len(x) (int)(x.size())
#define inf 1000'000'000'000'000'000LL
#define all(x) x.begin(), x.end()
#define low_bit(x) (x & (-x))
template<typename T>
using vec = vector<T>;
const int maxM = 701;
long long count_rectangles(std::vector<std::vector<i32>> a) {
int n = len(a);
int m = len(a[0]);
long long ans = 0;
vec<vec<bitset<maxM>>> b(n, vec<bitset<maxM>>(m));
for (int i = 1; i < n - 1; i++) {
for (int j = 1; j < m - 1; j++) {
b[i][j].reset();
int mx = a[i][j];
for (int l = i; l < n - 1; l++) {
mx = max(mx, a[l][j]);
if (mx >= min(a[i - 1][j], a[l + 1][j])) continue;
b[i][j][l] = true;
}
}
}
vec<vec<bitset<maxM>>> good(m, vec<bitset<maxM>>(m));
vec<vec<vec<int>>> maxVal(n, vec<vec<int>>(m, vec<int>(m, 0)));
for (int i = 1; i < n - 1; i++) {
for (int l = 1; l < m - 1; l++) {
for (int r = l; r < m - 1; r++) {
maxVal[i][l][r] = max(maxVal[i][l][r - 1], a[i][r]);
}
}
}
for (int l = 1; l < m - 1; l++) {
for (int r = l; r < m - 1; r++) {
for (int i = 0; i < n; i++) {
good[l][r][i] = maxVal[i][l][r] < min(a[i][l - 1], a[i][r + 1]);
}
}
}
vec<vec<vec<int>>> lowest(m, vec<vec<int>>(m, vec<int>(n, 0)));
for (int l = 1; l < m - 1; l++) {
for (int r = l; r < m - 1; r++) {
for (int i = n - 2; i >= 1; i--) {
if (!good[l][r][i]) continue;
lowest[l][r][i] = lowest[l][r][i + 1] + 1;
}
}
}
for (int i = 1; i < n - 1; i++) {
for (int j = 1; j < m - 1; j++) {
if (a[i][j] >= a[i - 1][j]) continue;
if (a[i][j] >= a[i][j - 1]) continue;
bitset<maxM> cur = b[i][j];
for (int k = j; k < m - 1; k++) {
cur &= b[i][k];
ans += (cur & ((good[j][k] << (maxM - i - lowest[j][k][i])) >> (maxM - i - lowest[j][k][i]))).count();
}
}
}
return ans;
}
# | 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... |