Submission #737917

#TimeUsernameProblemLanguageResultExecution timeMemory
737917bobthebuilderRectangles (IOI19_rect)C++17
72 / 100
5105 ms668800 KiB
#include "rect.h" #include<bits/stdc++.h> using namespace std; #define sz(x) (int)x.size() #define REP(i,n) for(int i=0;i<n;i++) #define REP1(i,n) for(int i=1;i<=n;i++) #define pb push_back #define lowb(x) (x&(-x)) #define ALL(_x) _x.begin(),_x.end() #define pii pair<int,int> #define f first #define s second #define SORT_UNIQUE(x) sort(ALL(x)),x.erase(unique(ALL(x)),x.end()) const int maxn=3e3+5; #define ll long long pii rng[maxn]; int par[maxn]; bool ded[maxn]; int find(int u){ if(par[u]==u) return u; return par[u]=find(par[u]); } void merge(int a,int b){ a=find(a),b=find(b); if(a==b) return; rng[b]={min(rng[a].f,rng[b].f),max(rng[a].s,rng[b].s)}; par[a]=b; } int pf[maxn]; vector<int> mp[maxn][maxn],m2[maxn][maxn]; int lok[maxn][maxn],rok[maxn][maxn]; vector<pii> get(vector<int> &val){ int n=sz(val); vector<pii> v; REP(i,n) rng[i]={i,i},par[i]=i; REP(j,n){ v.pb({val[j],j}); } sort(ALL(v)); vector<pii> vv; for(int j=0;j<sz(v);){ int p=j; vector<int> ps; while(j<sz(v) and v[p].f==v[j].f){ int z=v[j].s; if(z and val[z-1]<=val[z]) merge(z-1,z); if(z+1<n and val[z+1]<=val[z]) merge(z,z+1); ps.pb(z); ++j; } for(int x:ps){ auto z=rng[find(x)]; if(z.f and z.s!=n-1) { vv.pb(z); } } } SORT_UNIQUE(vv); return vv; } int ans=0; vector<vector<int>> a; void calc(int l,int r,int u,int d){ vector<int> vv; for(int i=u-1;i<=d+1;i++){ vv.pb(a[i][r]); } auto zz=get(vv); for(auto x:zz){ if(lok[x.f+u-1][x.s+u-1]<=l){ ++ans; } } } long long count_rectangles(std::vector<std::vector<int> > b) { a=b; int n=sz(a),m=sz(a[0]); REP1(i,n-2){ vector<int> val; REP(j,m) val.pb(a[i][j]); auto vv=get(val); for(auto x:vv){ mp[x.f][x.s].pb(i); } } REP(i,n) REP(j,n) lok[i][j]=rok[i][j]=-1; REP1(i,m-2){ vector<int> val; REP(j,n){ val.pb(a[j][i]); } auto vv=get(val); for(auto x:vv){ if(rok[x.f][x.s]<i-1){ lok[x.f][x.s]=i; } rok[x.f][x.s]=i; } REP1(j,i){ if(!sz(mp[j][i])) continue; int pv=mp[j][i][0]; REP1(z,sz(mp[j][i])-1){ int x=mp[j][i][z]; if(x>mp[j][i][z-1]+1){ calc(j,i,pv,mp[j][i][z-1]); pv=x; } } calc(j,i,pv,mp[j][i].back()); } } 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...