This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}
// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
public:
template<typename T>
_Debug& operator,(T val) {
cout << val << endl;
return *this;
}
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif
// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back
// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;
// ---------- END OF TEMPLATE ----------
vi row[2500],col[2500];
int pr[2500][2500],pc[2500][2500],cr[2500][2500],cc[2500][2500];
vpii x,y;
int bit[2500];
int getAns(int N) {
int i,j = 0,k;
int ans = 0;
sort(x.begin(),x.end());
for (i = 0; i < x.size(); i++) {
while ((j < y.size()) && (y[j].first <= x[i].first)) {
for (k = N-y[j].second; k < N; k += k & (-k)) bit[k]++;
j++;
}
for (k = N-x[i].second; k > 0; k -= k & (-k)) ans += bit[k];
}
for (i = 0; i < j; i++) {
for (k = N-y[i].second; k < N; k += k & (-k)) bit[k]--;
}
x.clear(),y.clear();
return ans;
}
long long int count_rectangles(vector<vector<int> > a) {
int i,j,ans = 0;
int n = a.size(),m = a[0].size();
for (i = 0; i < n; i++) row[i].pb(0);
for (i = 0; i < m; i++) col[i].pb(0);
for (i = 0; i < n-1; i++) {
for (j = 0; j < m-1; j++) {
int e = 0;
while (!row[i].empty() && (a[i][row[i].back()] <= a[i][j+1])) {
int u = row[i].back();
if ((u < j) && !e) {
if (pr[u+1][j] == i-1) cr[u+1][j]++;
else cr[u+1][j] = 1;
pr[u+1][j] = i,x.pb(mp(cr[u+1][j],j-u));
}
if (a[i][u] == a[i][j+1]) e = 1;
row[i].pop_back();
}
if (!row[i].empty() && (row[i].back() < j) && !e) {
int u = row[i].back();
if (pr[u+1][j] == i-1) cr[u+1][j]++;
else cr[u+1][j] = 1;
pr[u+1][j] = i,x.pb(mp(cr[u+1][j],j-u));
}
row[i].pb(j+1);
e = 0;
while (!col[j].empty() && (a[col[j].back()][j] <= a[i+1][j])) {
int u = col[j].back();
if ((u < i) && !e) {
if (pc[u+1][i] == j-1) cc[u+1][i]++;
else cc[u+1][i] = 1;
pc[u+1][i] = j,y.pb(mp(i-u,cc[u+1][i]));
}
if (a[u][j] == a[i+1][j]) e = 1;
col[j].pop_back();
}
if (!col[j].empty() && (col[j].back() < i) && !e) {
int u = col[j].back();
if (pc[u+1][i] == j-1) cc[u+1][i]++;
else cc[u+1][i] = 1;
pc[u+1][i] = j,y.pb(mp(i-u,cc[u+1][i]));
}
col[j].pb(i+1);
ans += getAns(m);
}
}
return ans;
}
Compilation message (stderr)
rect.cpp: In function 'int getAns(int)':
rect.cpp:66:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < x.size(); i++) {
~~^~~~~~~~~~
rect.cpp:67:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while ((j < y.size()) && (y[j].first <= x[i].first)) {
~~^~~~~~~~~~
# | 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... |