Submission #238777

#TimeUsernameProblemLanguageResultExecution timeMemory
238777dualityRectangles (IOI19_rect)C++14
100 / 100
4750 ms724216 KiB
#define DEBUG 0 #include <bits/stdc++.h> using namespace std; #if DEBUG // basic debugging macros int __i__,__j__; #define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl #define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl #define printVar(n) cout<<#n<<": "<<n<<endl #define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl #define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;} #define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;} // advanced debugging class // debug 1,2,'A',"test"; class _Debug { public: template<typename T> _Debug& operator,(T val) { cout << val << endl; return *this; } }; #define debug _Debug(), #else #define printLine(l) #define printLine2(l,c) #define printVar(n) #define printArr(a,l) #define print2dArr(a,r,c) #define print2dArr2(a,r,c,l) #define debug #endif // define #define MAX_VAL 999999999 #define MAX_VAL_2 999999999999999999LL #define EPS 1e-6 #define mp make_pair #define pb push_back // typedef typedef unsigned int UI; typedef long long int LLI; typedef unsigned long long int ULLI; typedef unsigned short int US; typedef pair<int,int> pii; typedef pair<LLI,LLI> plli; typedef vector<int> vi; typedef vector<LLI> vlli; typedef vector<pii> vpii; typedef vector<plli> vplli; // ---------- END OF TEMPLATE ---------- int l[2500][2500],r[2500][2500],u[2500][2500],d[2500][2500]; vi S,cand[2500][2500],cand2[2500][2500]; vector<pair<pii,pii> > poss; long long int count_rectangles(vector<vector<int> > a) { int i,j; int n = a.size(),m = a[0].size(); for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { int e = 0; while (!S.empty() && (a[i][S.back()] <= a[i][j])) { if (!e) cand[S.back()+1][j-1].pb(i); if (a[i][S.back()] == a[i][j]) e = 1; S.pop_back(); } if (S.empty()) l[i][j] = -1; else { if (!e) cand[S.back()+1][j-1].pb(i); l[i][j] = S.back(); } S.pb(j); } S.clear(); for (j = m-1; j >= 0; j--) { while (!S.empty() && (a[i][S.back()] < a[i][j])) S.pop_back(); if (S.empty()) r[i][j] = m; else r[i][j] = S.back(); S.pb(j); } S.clear(); } for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { int e = 0; while (!S.empty() && (a[S.back()][i] <= a[j][i])) { if (!e) cand2[S.back()+1][j-1].pb(i); if (a[S.back()][i] == a[j][i]) e = 1; S.pop_back(); } if (S.empty()) u[j][i] = -1; else { if (!e) cand2[S.back()+1][j-1].pb(i); u[j][i] = S.back(); } S.pb(j); } S.clear(); for (j = n-1; j >= 0; j--) { while (!S.empty() && (a[S.back()][i] < a[j][i])) S.pop_back(); if (S.empty()) d[j][i] = n; else d[j][i] = S.back(); S.pb(j); } S.clear(); } int ans = 0; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { if ((l[i][j] >= 0) && (r[i][j] < m) && (u[i][j] >= 0) && (d[i][j] < n)) poss.pb(mp(mp(l[i][j]+1,r[i][j]-1),mp(u[i][j]+1,d[i][j]-1))); } } sort(poss.begin(),poss.end()); for (i = 0; i < poss.size(); i++) { if ((i == 0) || (poss[i] != poss[i-1])) { int ll = poss[i].first.first,rr = poss[i].first.second,uu = poss[i].second.first,dd = poss[i].second.second; if (upper_bound(cand[ll][rr].begin(),cand[ll][rr].end(),dd) \ - lower_bound(cand[ll][rr].begin(),cand[ll][rr].end(),uu) == dd-uu+1) { if (upper_bound(cand2[uu][dd].begin(),cand2[uu][dd].end(),rr) \ - lower_bound(cand2[uu][dd].begin(),cand2[uu][dd].end(),ll) == rr-ll+1) ans++; } } } return ans; }

Compilation message (stderr)

rect.cpp: In function 'long long int count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:120:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < poss.size(); i++) {
                 ~~^~~~~~~~~~~~~
#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...