Submission #145437

#TimeUsernameProblemLanguageResultExecution timeMemory
145437MvCRectangles (IOI19_rect)C++14
49 / 100
2271 ms76940 KiB
#include "rect.h" #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") #include<bits/stdc++.h> #define rc(x) return cout<<x<<endl,0 #define pb push_back #define mkp make_pair #define in insert #define er erase #define fd find #define fr first #define sc second typedef long long ll; typedef long double ld; const ll INF=0x3f3f3f3f3f3f3f3f; const ll llinf=(1LL<<62); const int inf=(1<<30); const int nmax=7e2+5; const int mod=1e9+7; using namespace std; int n,m,a[nmax][nmax],i,j,t,x,y,rs; vector<pair<int,int> >pr[nmax]; vector<int>vc[nmax][nmax],st; bitset<nmax>bs,b[nmax][nmax]; ll count_rectangles(vector<vector<int> > A) { n=A.size(),m=A[0].size(); for(i=1;i<=n;i++)for(j=1;j<=m;j++)a[i][j]=A[i-1][j-1]; for(i=1;i<=n;i++) { st.clear(); for(j=1;j<=m;j++) { while(!st.empty() && a[i][st.back()]<a[i][j]) { if(st.back()+1<j) { pr[i].pb(mkp(st.back(),j)); vc[st.back()][j].pb(i); } st.pop_back(); } if(!st.empty() && st.back()+1<j) { pr[i].pb(mkp(st.back(),j)); vc[st.back()][j].pb(i); } while(!st.empty() && a[i][st.back()]==a[i][j])st.pop_back(); st.pb(j); } } for(i=1;i<=m;i++) { st.clear(); for(j=n;j>=1;j--) { while(!st.empty() && a[st.back()][i]<a[j][i]) { if(st.back()>j+1)b[j][i][st.back()]=1; st.pop_back(); } if(!st.empty() && st.back()>j+1)b[j][i][st.back()]=1; while(!st.empty() && a[st.back()][i]==a[j][i])st.pop_back(); st.pb(j); } } for(i=1;i<=n;i++) { for(j=0;j<pr[i].size();j++) { x=pr[i][j].fr,y=pr[i][j].sc; bs.set(); for(t=x+1;t<=y-1;t++) { bs&=b[i-1][t]; } for(t=0;t<vc[x][y].size();t++)if(vc[x][y][t]==i)break; for(;t<vc[x][y].size();t++) { if(vc[x][y][t]!=i && vc[x][y][t]!=vc[x][y][t-1]+1)break; rs+=bs[vc[x][y][t]+1]; } } } return rs; }

Compilation message (stderr)

rect.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization("O3")
 
rect.cpp:4:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization("unroll-loops")
 
rect.cpp: In function 'll count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:71:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(j=0;j<pr[i].size();j++)
           ~^~~~~~~~~~~~~
rect.cpp:79:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(t=0;t<vc[x][y].size();t++)if(vc[x][y][t]==i)break;
            ~^~~~~~~~~~~~~~~~
rect.cpp:80:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(;t<vc[x][y].size();t++)
         ~^~~~~~~~~~~~~~~~
#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...