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>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<db> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 998244353;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[] = { -1,-2,1,-2,2,-1,2,1 }, ddy[] = { -2,-1,-2,1,-1,2,1,2 };
int n,m;
ll count_rectangles(vector<Vi> a){
n=a.size(),m=a[0].size();
if(n>200)return 0;
vector<vector<Vi>> mxr(n,(vector<Vi> (m,Vi(m)))),mxc(m,(vector<Vi> (n,Vi(n)))), dr(n,(vector<Vi> (m,Vi(m)))),dc(m,(vector<Vi> (n,Vi(n))));
fup(i,0,n-1,1){
fup(j1,0,m-1,1){
mxr[i][j1][j1]=a[i][j1];
fup(j2,j1+1,m-1,1){
mxr[i][j1][j2]=max(mxr[i][j1][j2-1],a[i][j2]);
}
}
}
fup(j,0,m-1,1){
fup(i1,0,n-1,1){
mxc[j][i1][i1]=a[i1][j];
fup(i2,i1+1,n-1,1){
mxc[j][i1][i2]=max(mxc[j][i1][i2-1],a[i2][j]);
}
}
}
fup(i,1,n-2,1){
fup(j1,1,m-2,1){
fup(j2,j1,m-2,1){
int k=i;
dr[i][j1][j2]=i-1;
while(k<=n-2){
if(mxr[k][j1][j2]<a[k][j1-1] && mxr[k][j1][j2]<a[k][j2+1])dr[i][j1][j2]=k++;
else break;
}
}
}
}
fup(j,1,m-2,1){
fup(i1,1,n-2,1){
fup(i2,i1,n-2,1){
int k=j;
dc[j][i1][i2]=j-1;
while(k<=m-2){
if(mxc[k][i1][i2]<a[i1-1][k] && mxc[k][i1][i2]<a[i2+1][k])dc[j][i1][i2]=k++;
else break;
}
}
}
}
ll ans=0;
fup(x1,1,n-2,1){
fup(x2,x1,n-2,1){
fup(y1,1,m-2,1){
fup(y2,y1,m-2,1){
if(dr[x1][y1][y2]>=x2 && dc[y1][x1][x2]>=y2)ans++;
}
}
}
}
return ans;
}/*
int main() {
int n,m;
scanf("%d%d",&n,&m);
vector<Vi> v(n,Vi(m));
fup(i,0,n-1,1)fup(j,0,m-1,1)scanf("%d",&v[i][j]);
printf("%lld\n",count_rectangles(v));
}*/
Compilation message (stderr)
rect.cpp: In function 'll count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
rect.cpp:49:2: note: in expansion of macro 'fup'
49 | fup(i,0,n-1,1){
| ^~~
rect.cpp:10:30: warning: unnecessary parentheses in declaration of 'j1' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
rect.cpp:50:3: note: in expansion of macro 'fup'
50 | fup(j1,0,m-1,1){
| ^~~
rect.cpp:10:30: warning: unnecessary parentheses in declaration of 'j2' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
rect.cpp:52:4: note: in expansion of macro 'fup'
52 | fup(j2,j1+1,m-1,1){
| ^~~
rect.cpp:10:30: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
rect.cpp:57:2: note: in expansion of macro 'fup'
57 | fup(j,0,m-1,1){
| ^~~
rect.cpp:10:30: warning: unnecessary parentheses in declaration of 'i1' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
rect.cpp:58:3: note: in expansion of macro 'fup'
58 | fup(i1,0,n-1,1){
| ^~~
rect.cpp:10:30: warning: unnecessary parentheses in declaration of 'i2' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
rect.cpp:60:4: note: in expansion of macro 'fup'
60 | fup(i2,i1+1,n-1,1){
| ^~~
rect.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
rect.cpp:65:2: note: in expansion of macro 'fup'
65 | fup(i,1,n-2,1){
| ^~~
rect.cpp:10:30: warning: unnecessary parentheses in declaration of 'j1' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
rect.cpp:66:3: note: in expansion of macro 'fup'
66 | fup(j1,1,m-2,1){
| ^~~
rect.cpp:10:30: warning: unnecessary parentheses in declaration of 'j2' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
rect.cpp:67:4: note: in expansion of macro 'fup'
67 | fup(j2,j1,m-2,1){
| ^~~
rect.cpp:10:30: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
rect.cpp:77:2: note: in expansion of macro 'fup'
77 | fup(j,1,m-2,1){
| ^~~
rect.cpp:10:30: warning: unnecessary parentheses in declaration of 'i1' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
rect.cpp:78:3: note: in expansion of macro 'fup'
78 | fup(i1,1,n-2,1){
| ^~~
rect.cpp:10:30: warning: unnecessary parentheses in declaration of 'i2' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
rect.cpp:79:4: note: in expansion of macro 'fup'
79 | fup(i2,i1,n-2,1){
| ^~~
rect.cpp:10:30: warning: unnecessary parentheses in declaration of 'x1' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
rect.cpp:90:2: note: in expansion of macro 'fup'
90 | fup(x1,1,n-2,1){
| ^~~
rect.cpp:10:30: warning: unnecessary parentheses in declaration of 'x2' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
rect.cpp:91:3: note: in expansion of macro 'fup'
91 | fup(x2,x1,n-2,1){
| ^~~
rect.cpp:10:30: warning: unnecessary parentheses in declaration of 'y22' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
rect.cpp:92:4: note: in expansion of macro 'fup'
92 | fup(y1,1,m-2,1){
| ^~~
rect.cpp:10:30: warning: unnecessary parentheses in declaration of 'y2' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
rect.cpp:93:5: note: in expansion of macro 'fup'
93 | fup(y2,y1,m-2,1){
| ^~~
# | 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... |