제출 #251524

#제출 시각아이디문제언어결과실행 시간메모리
251524ryanseeRectangles (IOI19_rect)C++14
72 / 100
5050 ms909904 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=long long; using ld=long double; #define FOR(i,s,e) for(ll i=s;i<=ll(e);++i) #define DEC(i,s,e) for(ll i=s;i>=ll(e);--i) using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; #define LLINF ((long long)1e18) #define INF int(1e9+1e6) #define MAXN (2502) ll n, m, ans; vector<pair<int,int>> row[MAXN][MAXN], col[MAXN][MAXN]; 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){ reverse(all(v)); for(auto k:v) { if(abs(k-j)>1) e.pb({{i,j},{i,k}}); if(A[i][k]>=A[i][j]) break; } reverse(all(v)); while(v.size()&&A[i][v.back()]<=A[i][j])v.pop_back(); v.eb(j); } } FOR(j,0,m-1){ vector<int> v; FOR(i,0,n-1){ reverse(all(v)); for(auto k:v) { if(abs(k-i)>1) e.pb({{k,j},{i,j}}); if(A[k][j]>=A[i][j]) break; } reverse(all(v)); while(v.size()&&A[v.back()][j]<=A[i][j])v.pop_back(); v.eb(i); } } vector<ll> len(siz(e), 0); ll ind=0; for(auto i:e)if(i.f.f==i.s.f){ col[i.f.s][i.s.s].eb(i.f.f, ind++); }else{ assert(i.f.s==i.s.s); row[i.f.f][i.s.f].eb(i.f.s, ind++); } 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-1)FOR(j,0,n-1){ sort(all(row[i][j]),greater<>()); FOR(k,0,siz(row[i][j])-1){ if(k == 0 || row[i][j][k-1].f-1 != row[i][j][k].f) len[row[i][j][k].s]=1; else len[row[i][j][k].s]=len[row[i][j][k-1].s]+1; } } FOR(i,0,m-1)FOR(j,0,m-1){ sort(all(col[i][j]),greater<>()); FOR(k,0,siz(col[i][j])-1){ if(k == 0 || col[i][j][k-1].f-1 != col[i][j][k].f) len[col[i][j][k].s]=1; else len[col[i][j][k].s]=len[col[i][j][k-1].s]+1; } } FOR(i,0,n-2)FOR(j,1,m-2){ for(auto i1:r[i][j]){ for(auto i2:c[i+1][j-1]){ if(len[i2]>=e[i1].s.f-i-1&&len[i1]>=e[i2].s.s-(j-1)-1)++ 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...