이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "rect.h"
#include <bits/stdc++.h>
using namespace std;
int n, m;
int p[2505], lc[2505], rc[2505];
map<int, int> cnt[2][2505][2505];
int dir[2505][2505][4];
int arr[2505][2505];
int temp[2505];
void buildtree(int sz){
vector<int> v = {0};
for(int i = 1; i <= sz; i++){
vector<int> t;
while(temp[v.back()] < temp[i]){
t.push_back(v.back());
v.pop_back();
}
v.push_back(i);
for(int j = t.size() - 1; j > 0; j--){
p[t[j - 1]] = t[j];
}
if(!t.empty())p[t.back()] = i;
}
for(int i = v.size() - 1; i > 0; i--)
p[v[i]] = v[i - 1];
for(int i = 1; i <= sz; i++){
if(p[i] > i){
lc[p[i]] = i;
} else {
rc[p[i]] = i;
}
}
}
void travtree(int i1, int i2, int v, int l, int r){
if(l != 0 && r != (i1 == 1 ? n + 1 : m + 1) && r - l > 1 && temp[l] != temp[v] && temp[r] != temp[v]){
if(i1 == 0)
cnt[i1][i2][r - 1][r - l - 1]++;
else
cnt[i1][r - 1][i2][r - l - 1]++;
}
if(lc[v] != 0){
travtree(i1, i2, lc[v], l, v);
}
if(rc[v] != 0){
travtree(i1, i2, rc[v], v, r);
}
}
void build(){
for(int i = 1; i <= n; i++){
memset(lc, 0, sizeof lc);
memset(rc, 0, sizeof rc);
for(int j = 0; j <= m; j++)
temp[j] = arr[i][j];
buildtree(m);
travtree(0, i, 0, 0, m + 1);
}
for(int j = 1; j <= m; j++){
memset(lc, 0, sizeof lc);
memset(rc, 0, sizeof rc);
for(int i = 0; i <= n; i++)
temp[i] = arr[i][j];
buildtree(n);
travtree(1, j, 0, 0, n + 1);
}
}
long long count_rectangles(vector<vector<int> > a){
n = a.size();
m = a[0].size();
memset(arr, 0x3f, sizeof arr);
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
arr[i + 1][j + 1] = a[i][j];
}
}
build();
int res = 0;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
for(auto& x : cnt[0][i][j]){
auto it = cnt[0][i - 1][j].find(x.first);
if(it != cnt[0][i - 1][j].end())
x.second = 1 + it -> second;
}
for(auto& x : cnt[1][i][j]){
auto it = cnt[1][i][j - 1].find(x.first);
if(it != cnt[1][i][j - 1].end())
x.second = 1 + it -> second;
}
for(auto& x : cnt[0][i][j])
for(auto& y : cnt[1][i][j])
if(x.second >= y.first && y.second >= x.first)
res++;
}
}
return res;
}
# | 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... |