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"
using namespace std;
//macros
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define FOR(a,b) for(auto& a : b)
#define INF 1e9
#define pb push_back
#define fi first
#define se second
#define sz size()
const int MX=2502;
int n, m;
set<int> difW[MX][MX];
set<int> difH[MX][MX];
bool possible(int x, int y, int w, int h) {
RE(i,w) if(!difH[x+i][y].count(h)) return 0;
RE(i,h) if(!difW[x][y+i].count(w)) return 0;
return 1;
}
long long count_rectangles(vector<vi> a) {
n = a.sz; m = a[0].sz;
RE(i,n) {
stack<int> stck;
RE(j,m) {
while(!stck.empty() && a[i][stck.top()] < a[i][j]) {
stck.pop();
if(!stck.empty()) {
difH[i][stck.top()+1].insert(j-stck.top()-1);
}
}
if(!stck.empty() && a[i][stck.top()] == a[i][j])
stck.pop();
stck.push(j);
}
}
RE(j,m) {
stack<int> stck;
RE(i,n) {
while(!stck.empty() && a[stck.top()][j] < a[i][j]) {
stck.pop();
if(!stck.empty()) {
difW[stck.top()+1][j].insert(i-stck.top()-1);
}
}
if(!stck.empty() && a[stck.top()][j] == a[i][j])
stck.pop();
stck.push(i);
}
}
ll ans = 0;
RE(i,n) RE(j,m) {
FOR(w,difW[i][j]) FOR(h,difH[i][j]) {
if(possible(i,j,w,h))
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... |