제출 #155794

#제출 시각아이디문제언어결과실행 시간메모리
155794vanicRectangles (IOI19_rect)C++14
10 / 100
3569 ms838956 KiB
#include "rect.h" #include <cstdio> #include <vector> #include <algorithm> #include <queue> #include <unordered_map> #include <map> #include <stack> #include <set> #include <array> using namespace std; typedef long long ll; const int maxn=2521; int n, m; int l[maxn][maxn]; //vector < int > r[maxn][maxn], c[maxn][maxn]; map < int, int > r[maxn][maxn], c[maxn][maxn]; int rind[maxn][maxn], cind[maxn][maxn]; pair < int, int > red[maxn][maxn], stup[maxn][maxn]; int bio2[maxn][maxn], bio3[maxn][maxn]; vector < array < int, 4 > > bio; void upd1(int x){ stack < pair < int, int > > q; q.push(make_pair(1e8, -1)); for(int i=0; i<m; i++){ while(q.top().first<=l[x][i]){ q.pop(); } red[x][i].first=q.top().second+1; q.push(make_pair(l[x][i], i)); } while(!q.empty()){ q.pop(); } q.push(make_pair(1e8, m)); for(int i=m-1; i>-1; i--){ while(q.top().first<=l[x][i]){ q.pop(); } red[x][i].second=q.top().second-1; if(bio2[red[x][i].first][red[x][i].second]!=x+1){ bio2[red[x][i].first][red[x][i].second]=x+1; r[red[x][i].first][red[x][i].second][x]=r[red[x][i].first][red[x][i].second][rind[red[x][i].first][red[x][i].second]]+1; rind[red[x][i].first][red[x][i].second]=x; } q.push(make_pair(l[x][i], i)); } } void upd2(int x){ stack < pair < int, int > > q; q.push(make_pair(1e8, -1)); for(int i=0; i<n; i++){ while(q.top().first<=l[i][x]){ q.pop(); } stup[i][x].first=q.top().second+1; q.push(make_pair(l[i][x], i)); } while(!q.empty()){ q.pop(); } q.push(make_pair(1e8, n)); for(int i=n-1; i>-1; i--){ while(q.top().first<=l[i][x]){ q.pop(); } stup[i][x].second=q.top().second-1; if(bio3[stup[i][x].first][stup[i][x].second]!=x+1){ bio3[stup[i][x].first][stup[i][x].second]=x+1; c[stup[i][x].first][stup[i][x].second][x]=c[stup[i][x].first][stup[i][x].second][cind[stup[i][x].first][stup[i][x].second]]+1; cind[stup[i][x].first][stup[i][x].second]=x; } q.push(make_pair(l[i][x], i)); } } int binary(int x, vector < int > &l){ int lo=0, hi=l.size(), mid; while(lo<hi){ mid=(lo+hi)/2; if(l[mid]<x){ lo=mid+1; } else{ hi=mid; } } return lo; } void provjeri(int x, int y){ int r1, r2, c1, c2; r1=red[x][y].first; r2=red[x][y].second; c1=stup[x][y].first; c2=stup[x][y].second; if(r1==0 || c1==0 || r2==m-1 || c2==n-1){ return; } // int pos1=binary(c1, r[r1][r2]); // int pos2=binary(r1, c[c1][c2]); if(r[r1][r2][c2]-r[r1][r2][c1]==c2-c1 && c[c1][c2][r2]-c[c1][c2][r1]==r2-r1){ bio.push_back({r1, r2, c1, c2}); } } long long count_rectangles(vector < vector < int > > a){ n=a.size(); m=a[0].size(); for(int i=0; i<n; i++){ for(int j=0; j<m; j++){ l[i][j]=a[i][j]; } } for(int i=0; i<n; i++){ upd1(i); } for(int i=0; i<m; i++){ upd2(i); } for(int i=1; i<n-1; i++){ for(int j=1; j<m-1; j++){ provjeri(i, j); } } sort(bio.begin(), bio.end()); bio.erase(unique(bio.begin(), bio.end()), bio.end()); return bio.size(); } /* int main(){ scanf("%d%d", &n, &m); for(int i=0; i<n; i++){ for(int j=0; j<m; j++){ scanf("%d", &l[i][j]); } } for(int i=0; i<n; i++){ upd1(i); } for(int i=0; i<m; i++){ upd2(i); } for(int i=1; i<n-1; i++){ for(int j=1; j<m-1; j++){ provjeri(i, j); } } sort(bio.begin(), bio.end()); bio.erase(unique(bio.begin(), bio.end()), bio.end()); printf("%d\n", bio.size()); return 0; }*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...