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>
#include "rect.h"
#define ll long long
#define pb push_back
#define x first
#define y second
using namespace std;
int n,m;
map<pair<int,int>,set<pair<int,int>>> mp,mp2;
ll count_rectangles(vector<vector<int>> a)
{
//freopen("test.in","r",stdin);
//ios::sync_with_stdio(0); cin.tie(0);
int n=a.size(), m=a[0].size();
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
{
int k; cin>>k;
a[i].pb(k);
}for(int i=0;i<n;i++)
for(int j=0;j<m-1;j++)
{
int mx=a[i][j+1];
for(int k=j+2;k<m;k++)
{
if(mx>=a[i][j]) break;
if(mx>=a[i][k]) continue;
mx=a[i][k];
int num=1;
if(mp.count({i-1,j}))
{
auto it = mp[{i-1,j}].lower_bound({k,0});
if(it!=mp[{i-1,j}].end()) if((*it).x==k) num+=(*it).y;
}
mp[{i,j}].insert({k,num});
num=1;
if(mp.count({i-1,k}))
{
auto it = mp[{i-1,k}].lower_bound({j,0});
if(it!=mp[{i-1,k}].end()) if((*it).x==j) num+=(*it).y;
}
mp[{i,k}].insert({j,num});
}
}
ll ans=0;
for(int j=1;j<m-1;j++)
{
for(int i=0;i<n-1;i++)
{
int mx=a[i+1][j];
for(int k=i+2;k<n;k++)
{
if(mx>=a[i][j]) break;
if(mx>=a[k][j]) continue;
mx=a[k][j];
int num=1;
if(mp2.count({i,j-1}))
{
auto it = mp2[{i,j-1}].lower_bound({k,0});
if(it!=mp2[{i,j-1}].end()) if((*it).x==k) num+=(*it).y;
}
mp2[{i,j}].insert({k,num});
num=1;
if(mp2.count({k,j-1}))
{
auto it = mp2[{k,j-1}].lower_bound({i,0});
if(it!=mp2[{k,j-1}].end()) if((*it).x==i) num+=(*it).y;
}
mp2[{k,j}].insert({i,num});
auto it = mp[{k-1,j+1}].lower_bound({j-num,k-i-1});
for(;it!=mp[{k-1,j+1}].end();it++)
{
if((*it).x>j+1) break;
if((*it).y>=k-i-1) ans++;
}
}
}
}
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... |