제출 #726169

#제출 시각아이디문제언어결과실행 시간메모리
726169alvingogoRectangles (IOI19_rect)C++14
37 / 100
5030 ms82708 KiB
#include "rect.h" #include <bits/stdc++.h> #define fs first #define sc second using namespace std; typedef pair<int,int> pii; struct BIT{ int n; vector<int> bt; BIT(int x){ n=x; bt.resize(x); } void update(int x,int y){ for(;x<=n;x+=(x&-x)){ bt[x]+=y; } } int query(int x){ int ans=0; for(;x>0;x-=(x&-x)){ ans+=bt[x]; } return ans; } }; long long count_rectangles(vector<vector<int> > v) { int n=v.size(); int m=v[0].size(); if(n<=2 || m<=2){ return 0; } vector<vector<pii> > az(n),bz(m); for(int i=1;i<n-1;i++){ vector<pair<int,int> > gg; vector<int> vis(m),up(m),down(m); for(int j=0;j<m;j++){ gg.push_back({v[i][j],j}); } sort(gg.begin(),gg.end()); for(auto h:gg){ int x=h.sc-1,y=h.sc+1; int l=h.sc,r=h.sc; if(x<0 || !vis[x]){ } else{ l=up[x]; } if(y>=m || !vis[y]){ } else{ r=down[y]; } vis[h.sc]=1; up[h.sc]=l; down[h.sc]=r; down[l]=r; up[r]=l; if(l!=0 && r!=m-1 && (v[i][r+1]>h.fs && v[i][l-1]>h.fs)){ az[i].push_back({l,r}); } } } for(int i=1;i<m-1;i++){ vector<pair<int,int> > gg; vector<int> vis(n),up(n),down(n); for(int j=0;j<n;j++){ gg.push_back({v[j][i],j}); } sort(gg.begin(),gg.end()); for(auto h:gg){ int x=h.sc-1,y=h.sc+1; int l=h.sc,r=h.sc; if(x<0 || !vis[x]){ } else{ l=up[x]; } if(y>=n || !vis[y]){ } else{ r=down[y]; } vis[h.sc]=1; up[h.sc]=l; down[h.sc]=r; down[l]=r; up[r]=l; if(l!=0 && r!=n-1 && (v[r+1][i]>h.fs && v[l-1][i]>h.fs)){ bz[i].push_back({l,r}); } } } vector<pair<pii,pii> > c,d; map<pii,int> mp; for(int i=1;i<n-1;i++){ map<pii,int> tmp; for(auto h:az[i]){ tmp[h]=1; if(mp.find(h)==mp.end()){ mp[h]=i; } } if(i>1){ for(auto h:az[i-1]){ if(tmp.find(h)==tmp.end()){ c.push_back({h,{mp[h],i-1}}); mp.erase(h); } } } } for(auto h:mp){ c.push_back({h.fs,{h.sc,n-2}}); } mp.clear(); for(int i=1;i<m-1;i++){ map<pii,int> tmp; for(auto h:bz[i]){ tmp[h]=1; if(mp.find(h)==mp.end()){ mp[h]=i; } } if(i>1){ for(auto h:bz[i-1]){ if(tmp.find(h)==tmp.end()){ d.push_back({h,{mp[h],i-1}}); mp.erase(h); } } } } for(auto h:mp){ d.push_back({h.fs,{h.sc,m-2}}); } int ans=0; for(auto y:c){ for(auto z:d){ if(y.fs.fs>=z.sc.fs && y.fs.sc<=z.sc.sc && z.fs.fs>=y.sc.fs && z.fs.sc<=y.sc.sc){ 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...