Submission #1227051

#TimeUsernameProblemLanguageResultExecution timeMemory
1227051LemserRectangles (IOI19_rect)C++20
10 / 100
10 ms14408 KiB
#include "rect.h" #include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx2") #pragma GCC target("popcnt") using namespace std; using ll = long long; using ull = unsigned long long; using lld = long double; using ii = pair<int,int>; using pll = pair<ll, ll>; using vi = vector<int>; using vll = vector<ll>; using vii = vector<ii>; using vpll = vector<pll>; using vlld = vector<lld>; #define all(x) x.begin(),x.end() #define lsb(x) x&(-x) #define gcd(a,b) __gcd(a,b) #define sz(x) (int)x.size() #define pb push_back #define fi first #define se second #define fls cout.flush() #define fore(i, l, r) for (auto i = l; i < r; i++) #define fo(i, n) fore (i, 0, n) #define forex(i, r, l) for (auto i = r-1; i >= l; i--) #define ffo(i, n) forex (i, n, 0) bool cmin(ll &a, ll b) { if (b < a) { a=b; return 1; } return 0; } bool cmax(ll &a, ll b) { if (b > a) { a=b; return 1; } return 0; } const ll INF = 1e18; const int mod = 1e9 + 7, LOG = 20; const int N = 505; ll vis[N][N][N]; ll count_rectangles(vector<vector<int> > a) { ll n = a.size(), m = a[0].size(), ans = 0; fo (i, n) { fo (l, m) { fo (r, m) { vis[i][l][r] = 0; } } } vector<vll> down(n, vll(m)), up(n, vll(m)); fo (j, m) { stack<ll> stk; stk.push(-1); fo (i, n) { while (stk.top() != -1 && a[stk.top()][j] < a[i][j]) stk.pop(); up[i][j] = stk.top(); stk.push(i); } while (stk.size()) stk.pop(); stk.push(n); ffo (i, n) { while (stk.top() != n && a[stk.top()][j] < a[i][j]) stk.pop(); down[i][j] = stk.top(); stk.push(i); } } forex (i, n-1, 1) { vll L(m), R(m); stack<ll> stk; stk.push(-1); fo (j, m) { while (stk.top() != -1 && a[i][stk.top()] <= a[i][j]) stk.pop(); L[j] = stk.top() + 1; stk.push(j); } while (stk.size()) stk.pop(); stk.push(m); ffo (j, m) { while (stk.top() != m && a[i][stk.top()] < a[i][j]) stk.pop(); R[j] = stk.top() - 1; stk.push(j); } fo (j, m) { if (L[j] < 1 || m-2 < R[j]) continue; vis[i][L[j]][R[j]] = 1; ll mn = n-1; fore (j2, L[j], R[j]+1) mn = min(mn, down[i-1][j2]); fore (i2, i, n-1) { ll mx = 0; fore (j2, L[j], R[j]+1) mx = max(mx, up[i2+1][j2]); if (mx >= i) continue; if (mn <= i2 || vis[i2][L[j]][R[j]] == 0) break; 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...