제출 #144080

#제출 시각아이디문제언어결과실행 시간메모리
144080LyestriaRectangles (IOI19_rect)C++14
10 / 100
1659 ms157976 KiB
#include "rect.h" #include<bits/stdc++.h> using namespace std; const int mn=2510; struct seg{ int seg[mn*2]; void up(int a,int b){ seg[a+=mn]=b; for(a>>=1;a;a>>=1)seg[a]=min(seg[a<<1],seg[(a<<1)^1]); } int qu(int a,int b){ int ans=0x3f3f3f3f; for(a+=mn,b+=mn;a<=b;a>>=1,b>>=1){ if(a&1)ans=min(ans,seg[a++]); if(!(b&1))ans=min(ans,seg[b--]); } return ans; } }; seg lef[mn],rig[mn],up[mn],dow[mn]; long long count_rectangles(std::vector<std::vector<int> > a) { int n=a.size(),m=a[0].size(); int i,j; for(i=0;i<n;i++){ stack<int>s; for(j=0;j<m;j++){ while(s.size()&&a[i][s.top()]<=a[i][j])rig[s.top()].up(i,j),s.pop(); s.push(j); } while(s.size())rig[s.top()].up(i,j),s.pop(); for(j=m-1;j>=0;j--){ while(s.size()&&a[i][s.top()]<=a[i][j])lef[s.top()].up(i,-j),s.pop(); s.push(j); } while(s.size())lef[s.top()].up(i,-j),s.pop(); } for(i=0;i<m;i++){ stack<int>s; for(j=0;j<n;j++){ while(s.size()&&a[s.top()][i]<=a[j][i])dow[s.top()].up(i,j),s.pop(); s.push(j); } while(s.size())dow[s.top()].up(i,j),s.pop(); for(j=n-1;j>=0;j--){ while(s.size()&&a[s.top()][i]<=a[j][i])up[s.top()].up(i,-j),s.pop(); s.push(j); } while(s.size())up[s.top()].up(i,-j),s.pop(); } int ans=0; for(i=1;i<n-1;i++){ for(j=1;j<m-1;j++){ int d,u,l,r; d=dow[i].qu(j,j); u=-up[i].qu(j,j); l=-lef[j].qu(i,i); r=rig[j].qu(i,i); if(l==-1||u==-1||r==m||d==n)continue; if(rig[l].qu(u+1,d-1)<r)continue; if(-lef[r].qu(u+1,d-1)>l)continue; if(dow[u].qu(l+1,r-1)<d)continue; if(-up[d].qu(l+1,r-1)>u)continue; ans++; } } return ans; }
#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...