제출 #251534

#제출 시각아이디문제언어결과실행 시간메모리
251534ryanseeRectangles (IOI19_rect)C++14
100 / 100
3843 ms1048576 KiB
#include "rect.h" #include "bits/stdc++.h" using namespace std; #define FAST ios_base::sync_with_stdio(false); cin.tie(0); #define pb push_back #define eb emplace_back #define ins insert #define f first #define s second #define cbr cerr<<"hi\n" #define mmst(x, v) memset((x), v, sizeof ((x))) #define siz(x) ll(x.size()) #define all(x) (x).begin(), (x).end() #define lbd(x,y) (lower_bound(all(x),y)-x.begin()) #define ubd(x,y) (upper_bound(all(x),y)-x.begin()) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng) inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); } using ll=int; using ld=long double; #define FOR(i,s,e) for(int i=s;i<=ll(e);++i) #define DEC(i,s,e) for(int i=s;i>=ll(e);--i) using pi=pair<int,int>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; #define LLINF ((long long)1e18) #define INF int(1e9+1e6) #define MAXN (2500) ll n, m, ans; vector<int> r[MAXN][MAXN], c[MAXN][MAXN]; vector<dpi> e; long long count_rectangles(std::vector<std::vector<int>> A) { n = siz(A), m=siz(A[0]); FOR(i,0,n-1){ vector<int> v; DEC(j,m-1,0){ DEC(k,siz(v)-1,0) { if(abs(v[k]-j)>1) e.pb({{i,j},{i,v[k]}}); if(A[i][v[k]]>=A[i][j]) break; } while(v.size()&&A[i][v.back()]<=A[i][j])v.pop_back(); v.eb(j); } v.clear(); } FOR(j,0,m-1){ vector<int> v; FOR(i,0,n-1){ DEC(k,siz(v)-1,0) { if(abs(v[k]-i)>1) e.pb({{v[k],j},{i,j}}); if(A[v[k]][j]>=A[i][j]) break; } while(v.size()&&A[v.back()][j]<=A[i][j])v.pop_back(); v.eb(i); } v.clear(); } A.clear(); vector<int> len(siz(e), 0); ll ind=0; for(auto i:e)if(i.f.f==i.s.f){ c[i.f.s][i.s.s].eb(ind++);//.f.f }else{ r[i.f.f][i.s.f].eb(ind++);//.f.s } FOR(i,0,n-1)FOR(j,0,n-1){ DEC(k,siz(r[i][j])-1,0){ if(k == siz(r[i][j])-1 || e[r[i][j][k+1]].f.s-1 != e[r[i][j][k]].f.s) len[r[i][j][k]]=1; else len[r[i][j][k]]=len[r[i][j][k+1]]+1; } } FOR(i,0,m-1)FOR(j,0,m-1){ DEC(k,siz(c[i][j])-1,0){ if(k == siz(c[i][j])-1 || e[c[i][j][k+1]].f.f-1 != e[c[i][j][k]].f.f) len[c[i][j][k]]=1; else len[c[i][j][k]]=len[c[i][j][k+1]]+1; } } FOR(i,0,n-1)FOR(j,0,n-1)r[i][j].clear(); FOR(i,0,m-1)FOR(j,0,m-1)c[i][j].clear(); FOR(i,0,siz(e)-1){ if(e[i].f.s==e[i].s.s) r[e[i].f.f][e[i].f.s].eb(i); else c[e[i].f.f][e[i].f.s].eb(i); } FOR(i,0,n-3)FOR(j,1,m-2){ for(auto i1:r[i][j]){ ll crit1=e[i1].s.f-i-1; for(auto i2:c[i+1][j-1]){ if(len[i1]<e[i2].s.s-(j-1)-1)break; if(len[i2]>=crit1)++ 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...