Submission #144311

#TimeUsernameProblemLanguageResultExecution timeMemory
144311LyestriaRectangles (IOI19_rect)C++14
Compilation error
0 ms0 KiB
#include "rect.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; const short mn=2510; struct seg{ short seg[mn][12]; inline void up(short a,short b){ seg[a][0]=b; } inline void init(){ for(short i=1;i<12;i++){ for(short j=0;j+(1<<i-1)<mn;j++){ seg[j][i]=min(seg[j][i-1],seg[j+(1<<i-1)][i-1]); } } } inline short qu(short a,short b){ short ret=0x3f3f; for(short i=11;i>=0;i--){ if(a+(1<<i)<=b+1)ret=min(ret,seg[a][i]),a+=(1<<i); } return ret; } }; seg lef[mn],rig[mn],up[mn],dow[mn]; short elef[mn][mn],erig[mn][mn],eup[mn][mn],edow[mn][mn]; unordered_set<ll>ss; long long hsh(ll a,ll b,ll c,ll d){ return (a<<48)|(b<<32)|(c<<16)|d; } long long count_rectangles(std::vector<std::vector<int> > a) { short n=a.size(),m=a[0].size(); short i,j; stack<int>s; for(i=0;i<n;i++){ 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(j=0;j<m;j++){ while(s.size()&&a[i][s.top()]<a[i][j])erig[i][s.top()]=j,s.pop(); s.push(j); } while(s.size())erig[i][s.top()]=j,s.pop(); for(j=m-1;j>=0;j--){ while(s.size()&&a[i][s.top()]<a[i][j])elef[i][s.top()]=j,s.pop(); s.push(j); } while(s.size())elef[i][s.top()]=j,s.pop(); } for(i=0;i<m;i++){ 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(); for(j=0;j<n;j++){ while(s.size()&&a[s.top()][i]<a[j][i])edow[s.top()][i]=j,s.pop(); s.push(j); } while(s.size())edow[s.top()][i]=j,s.pop(); for(j=n-1;j>=0;j--){ while(s.size()&&a[s.top()][i]<a[j][i])eup[s.top()][i]=j,s.pop(); s.push(j); } while(s.size())eup[s.top()][i]=j,s.pop(); } for(i=0;i<mn;i++)lef[i].init(),rig[i].init(),up[i].init(),dow[i].init(); int ans=0; for(i=1;i<n-1;i++){ for(j=1;j<m-1;j++){ if(ss.find(hsh(d,u,l,r))!=ss.end())continue; short d,u,l,r; d=edow[i][j]; u=eup[i][j]; l=elef[i][j]; r=erig[i][j]; 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; ss.insert(hsh(d,u,l,r)); } } return ss.size(); }

Compilation message (stderr)

rect.cpp: In member function 'void seg::init()':
rect.cpp:13:34: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
             for(short j=0;j+(1<<i-1)<mn;j++){
                                 ~^~
rect.cpp:14:54: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
                 seg[j][i]=min(seg[j][i-1],seg[j+(1<<i-1)][i-1]);
                                                     ~^~
rect.cpp: In function 'long long int count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:84:27: error: 'd' was not declared in this scope
            if(ss.find(hsh(d,u,l,r))!=ss.end())continue;
                           ^
rect.cpp:84:29: error: 'u' was not declared in this scope
            if(ss.find(hsh(d,u,l,r))!=ss.end())continue;
                             ^
rect.cpp:84:31: error: 'l' was not declared in this scope
            if(ss.find(hsh(d,u,l,r))!=ss.end())continue;
                               ^
rect.cpp:84:33: error: 'r' was not declared in this scope
            if(ss.find(hsh(d,u,l,r))!=ss.end())continue;
                                 ^
rect.cpp:81:8: warning: unused variable 'ans' [-Wunused-variable]
    int ans=0;
        ^~~