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>
using namespace std;
#define sz(x) (int)x.size()
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define lowb(x) (x&(-x))
#define ALL(x) x.begin(),x.end()
#define pii pair<int,int>
#define f first
#define s second
#define SORT_UNIQUE(x) sort(ALL(x)),x.erase(unique(ALL(x)),x.end())
const int maxn=3e3+5;
#define ll long long
pii rng[maxn];
int par[maxn];
bool ded[maxn];
int find(int u){
if(par[u]==u) return u;
return par[u]=find(par[u]);
}
void merge(int a,int b){
a=find(a),b=find(b);
if(a==b) return;
rng[b]={min(rng[a].f,rng[b].f),max(rng[a].s,rng[b].s)};
par[a]=b;
}
long long count_rectangles(std::vector<std::vector<int> > a) {
int n=sz(a),m=sz(a[0]);
map<pii,vector<int>> mp;
REP1(i,n-2){
vector<pii> v;
REP(j,m) rng[j]={j,j},par[j]=j;
REP(j,m){
if(a[i-1][j]<=a[i][j] or a[i+1][j]<=a[i][j]){
ded[j]=1;
continue;
}
v.pb({a[i][j],j});
}
ded[0]=ded[m-1]=1;
sort(ALL(v));
vector<pii> vv;
for(int j=0;j<sz(v);){
int p=j;
vector<int> ps;
while(j<sz(v) and v[p].f==v[j].f){
int z=v[j].s;
if(!ded[z-1] and a[i][z-1]<=a[i][z]) merge(z-1,z);
if(!ded[z+1] and a[i][z+1]<=a[i][z]) merge(z,z+1);
ps.pb(z);
++j;
}
for(int x:ps){
auto z=rng[find(x)];
if(z.f and z.s!=m-1) vv.pb(z);
}
}
SORT_UNIQUE(vv);
for(auto x:vv){
mp[x].pb(i);
}
return sz(vv);
}
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... |