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"
#define st first
#define nd second
#define pb push_back
#define eb emplace_back
#define pp pop_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vii = vector<pii>;
using ll = long long;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
void debug(){cerr<<"\n";}
template<typename H, typename... T>
void debug(H h, T... t){
cerr<<h;
if(sizeof...(t))cerr<<", ";
debug(t...);
}
#define deb(x...) cerr<<#x<<" = ";debug(x);
const int N=2505;
ll count_rectangles(std::vector<std::vector<int> > tab) {
int n=tab.size(), m=tab[0].size();
vector<vector<bitset<N> > > par(n, vector<bitset<N> >(m));
for(int i=1; i<m-1; i++){
vi V={0};
for(int j=1; j<n; j++){
while(V.size() && tab[j][i]>tab[V.back()][i]){
if(V.back()!=j-1)par[j][i][V.back()]=1;
V.pp();
}
if(V.size() && V.back()!=j-1)par[j][i][V.back()]=1;
if(V.size() && tab[V.back()][i]==tab[j][i])V.pp();
V.pb(j);
}
}
/*for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
//deb(i, j);
for(int k:par[i][j]){
//deb(k);
}
}
}*/
vector<pii> prv;
vi dp2;
ll ans=0;
for(int r=1; r<n-1; r++){
vector<pii> akt;
vi dp;
vi V={m-1};
for(int j=m-2; j>=0; j--){
while(V.size() && tab[r][j]>tab[r][V.back()]){
if(V.back()!=j+1){
akt.eb(j, V.back());
}
V.pp();
}
if(V.size() && V.back()!=j+1){
akt.eb(j, V.back());
}
if(V.size() && tab[r][V.back()]==tab[r][j])V.pp();
V.pb(j);
}
dp.resize(akt.size(), 1);
int wsk=0;
for(int i=0; i<akt.size(); i++){
while(wsk<prv.size() && (akt[i].st<prv[wsk].st
|| (akt[i].st==prv[wsk].st && akt[i].nd>prv[wsk].nd)))wsk++;
if(wsk<prv.size() && akt[i]==prv[wsk])dp[i]+=dp2[wsk];
}
vi wsk2(m);
vector<int> S;
vector<bitset<N> > b(akt.size());
for(int i=0; i<akt.size(); i++){
//deb(r, i, akt[i].st, akt[i].nd, dp[i]);
for(int k=r-1; k>=r-dp[i]; k--)b[i][k]=1;
int pocz=akt[i].st+1;
/*while(S.size()){
int a=S.back();
if(akt[a].st>=akt[i].nd)break;
S.pp();
for(;pocz<=akt[a].st;pocz++){
b[i]&=par[r+1][pocz];
}
b[i]&=b[a];
pocz=akt[a].nd;
}*/
S.pb(i);
for(;pocz<akt[i].nd;pocz++){
b[i]&=par[r+1][pocz];
}
ans+=b[i].count();
/*for(int k=r-1; k>=r-dp[i]; k--){
if(b[i][k]){
//deb(r, akt[i].st, akt[i].nd, k);
ans++;
}
}*/
}
prv=akt;
dp2=dp;
}
return ans;
}
Compilation message (stderr)
rect.cpp: In function 'll count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:74:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | for(int i=0; i<akt.size(); i++){
| ~^~~~~~~~~~~
rect.cpp:75:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | while(wsk<prv.size() && (akt[i].st<prv[wsk].st
| ~~~^~~~~~~~~~~
rect.cpp:77:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | if(wsk<prv.size() && akt[i]==prv[wsk])dp[i]+=dp2[wsk];
| ~~~^~~~~~~~~~~
rect.cpp:82:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | for(int i=0; i<akt.size(); i++){
| ~^~~~~~~~~~~
# | 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... |