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;
long long count_rectangles(vector<vector<int>> tab) {
int n = tab.size();
int m = tab[0].size();
vector<vector<int>> lft(n, vector<int>(m));
vector<vector<int>> up(n, vector<int>(m));
vector<vector<vector<int>>> pos;
pos.resize(n, vector<vector<int>>(m));
for(int i = 0; i < n; i++){
lft[i][0] = -1;
for(int j = 1; j < m; j++){
int pt = j-1;
while(pt!=-1&&tab[i][pt]<tab[i][j]){
pt = lft[i][pt];
pos[i][j-1].push_back(pt);
}
if(pos[i][j-1].size()&&pos[i][j-1].back()==-1){
pos[i][j-1].pop_back();
}
lft[i][j] = pt;
if(tab[i][j]<=tab[i][j-1]){
pos[i][j-1].resize(0);
}
}
}
vector<int> time(m+10);
int wyn = 0;
int cur = 10;
for(int i = 0; i < m-1; i++){
for(int j = 0; j < n; j++){
cur+=2;
int pt = j-1;
vector<int> pos2;
while(pt!=-1&&tab[pt][i]<tab[j][i]){
pos2.push_back(pt);
pt = up[pt][i];
}
//cout<<j<<" "<<i<<" "<<pos2.size()<<'\n';
if(pos2.size()){
//cout<<pos2[0]<<" "<<pos[pos2[0]][i].size()<<'\n';
for(auto it:pos[pos2[0]][i]){
if(pos2[0]!=0){
time[it] = cur;
wyn++;
//cout<<j<<" "<<i<<" "<<pos2[0]<<" "<<it<<'\n';
}
}
}
for(int k = 1; k < (int)pos2.size(); k++){
for(auto it:pos[pos2[k]][i]){
if(time[it]==cur){
if(pos2[k]!=0){
time[it]++;
wyn++;
//cout<<j<<" "<<i<<" "<<pos2[k]<<" "<<it<<'\n';
}
}
}
cur++;
}
if(pos2.size()){
pos[j][i].resize(0);
for(auto it:pos[pos2.back()][i]){
if(time[it]==cur){
pos[j][i].push_back(it);
}
}
}
up[j][i] = pt;
}
}
/*
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cout<<i<<" "<<j<<": ";
for(auto it:pos[i][j]) cout<<it<<" ";
cout<<'\n';
}
}
*/
return wyn;
}
# | 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... |