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 <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <map>
#include <stack>
#include <set>
#include <array>
#include <bitset>
using namespace std;
typedef long long ll;
const int maxn=2503, mod=200002027;
int n, m;
int l[maxn][maxn];
//vector < int > r[maxn][maxn], c[maxn][maxn];
unordered_map < int, int > r, c;
int rind[maxn][maxn], cind[maxn][maxn];
pair < int, int > red[maxn][maxn], stup[maxn][maxn];
int bio2[maxn][maxn], bio3[maxn][maxn];
//vector < array < int, 4 > > bio;
bitset < mod > bio;
inline int hashiraj(ll a, ll b, ll c){
return (a*maxn*maxn+b*maxn+c)%mod;
}
inline int hashah(ll a, ll b, ll c, ll d){
return (a*maxn*maxn*maxn+b*maxn*maxn+c*maxn+d)%mod;
}
void upd1(int x){
stack < pair < int, int > > q;
q.push(make_pair(1e8, -1));
for(int i=0; i<m; i++){
while(q.top().first<=l[x][i]){
q.pop();
}
red[x][i].first=q.top().second+1;
q.push(make_pair(l[x][i], i));
}
while(!q.empty()){
q.pop();
}
q.push(make_pair(1e8, m));
for(int i=m-1; i>-1; i--){
while(q.top().first<=l[x][i]){
q.pop();
}
red[x][i].second=q.top().second-1;
if(bio2[red[x][i].first][red[x][i].second]!=x+1){
bio2[red[x][i].first][red[x][i].second]=x+1;
rind[red[x][i].first][red[x][i].second]++;
r[hashiraj(red[x][i].first, red[x][i].second, x)]=rind[red[x][i].first][red[x][i].second];
}
q.push(make_pair(l[x][i], i));
}
}
void upd2(int x){
stack < pair < int, int > > q;
q.push(make_pair(1e8, -1));
for(int i=0; i<n; i++){
while(q.top().first<=l[i][x]){
q.pop();
}
stup[i][x].first=q.top().second+1;
q.push(make_pair(l[i][x], i));
}
while(!q.empty()){
q.pop();
}
q.push(make_pair(1e8, n));
for(int i=n-1; i>-1; i--){
while(q.top().first<=l[i][x]){
q.pop();
}
stup[i][x].second=q.top().second-1;
if(bio3[stup[i][x].first][stup[i][x].second]!=x+1){
bio3[stup[i][x].first][stup[i][x].second]=x+1;
cind[stup[i][x].first][stup[i][x].second]++;
c[hashiraj(stup[i][x].first, stup[i][x].second, x)]=cind[stup[i][x].first][stup[i][x].second];
}
q.push(make_pair(l[i][x], i));
}
}
bool provjeri(int x, int y){
int r1, r2, c1, c2;
r1=red[x][y].first;
r2=red[x][y].second;
c1=stup[x][y].first;
c2=stup[x][y].second;
if(r1==0 || c1==0 || r2==m-1 || c2==n-1){
return 0;
}
if(r[hashiraj(r1, r2, c2)]!=0 && r[hashiraj(r1, r2, c1)]!=0
&& c[hashiraj(c1, c2, r2)]!=0 && c[hashiraj(c1, c2, r1)]!=0
&& r[hashiraj(r1, r2, c2)]-r[hashiraj(r1, r2, c1)]==c2-c1 && c[hashiraj(c1, c2, r2)]-c[hashiraj(c1, c2, r1)]==r2-r1){
if(!bio[hashah(r1, r2, c1, c2)]){
bio[hashah(r1, r2, c1, c2)]=1;
return 1;
}
}
return 0;
}
long long count_rectangles(vector < vector < int > > a){
n=a.size();
m=a[0].size();
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
l[i][j]=a[i][j];
}
}
for(int i=0; i<n; i++){
upd1(i);
}
for(int i=0; i<m; i++){
upd2(i);
}
int br=0;
for(int i=1; i<n-1; i++){
for(int j=1; j<m-1; j++){
br+=provjeri(i, j);
}
}
return br;
}
/*
int main(){
scanf("%d%d", &n, &m);
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
scanf("%d", &l[i][j]);
}
}
for(int i=0; i<n; i++){
upd1(i);
}
for(int i=0; i<m; i++){
upd2(i);
}
for(int i=1; i<n-1; i++){
for(int j=1; j<m-1; j++){
provjeri(i, j);
}
}
sort(bio.begin(), bio.end());
bio.erase(unique(bio.begin(), bio.end()), bio.end());
printf("%d\n", (int)bio.size());
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... |