Submission #293747

#TimeUsernameProblemLanguageResultExecution timeMemory
293747egekabasRectangles (IOI19_rect)C++14
37 / 100
1138 ms473720 KiB
#include "rect.h" #include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() #define ff first #define ss second #define pb push_back #define mp make_pair using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> pll; typedef pair<ull, ull> pull; typedef pair<int, int> pii; typedef pair<ld, ld> pld; bitset<200> lef[200][200]; bitset<200> down[200][200]; bitset<200> lefr[200][200][200]; bitset<200> downr[200][200][200]; int n, m; ll solven3(vector<std::vector<int> > a){ vector<int> bad; for(int i = 0; i < m; ++i) if(a[1][i] >= a[0][i] || a[1][i] >= a[2][i]){ bad.pb(i); } vector<pii> vec; ll ans = 0; for(int i = m-1; i >= 0; --i){ while(vec.size()){ int idx1 = upper_bound(all(bad), i)-bad.begin(); int idx2 = int(lower_bound(all(bad), vec.back().ss)-bad.begin())-1; if(idx1 > idx2 && vec.back().ss != i+1) ++ans; if(vec.back().ff > a[1][i]) break; vec.pop_back(); } vec.pb({a[1][i], i}); } return ans; } long long count_rectangles(vector<std::vector<int> > a) { n = a.size(); m = a[0].size(); if(n <= 2) return 0; if(n <= 3) return solven3(a); for(int i = 0; i < n; ++i) for(int j = 0; j < m; ++j){ int maxi = -1; for(int k = j+1; k < m; ++k){ if(a[i][j] <= maxi) break; lef[i][j][k] = a[i][k] > maxi; maxi = max(maxi, a[i][k]); } } for(int i = 0; i < n; ++i) for(int j = 0; j < m; ++j){ int maxi = -1; for(int k = i+1; k < n; ++k){ if(a[i][j] <= maxi) break; down[i][j][k] = a[k][j] > maxi; maxi = max(maxi, a[k][j]); } } for(int i = 0; i < n; ++i) for(int j = 0; j < m; ++j) for(int k = j; k < m; ++k){ if(j == k) downr[i][j][k] = down[i][j]; else downr[i][j][k] = (down[i][k]&downr[i][j][k-1]); } for(int i = 0; i < m; ++i) for(int j = 0; j < n; ++j) for(int k = j; k < n; ++k){ if(j == k) lefr[i][j][k] = lef[j][i]; else lefr[i][j][k] = (lef[k][i]&lefr[i][j][k-1]); } ll ans = 0; for(int i1 = 1; i1 < n-1; ++i1) for(int i2 = i1; i2 < n-1; ++i2) for(int j1 = 1; j1 < m-1; ++j1) for(int j2 = j1; j2 < m-1; ++j2){ ans += downr[i1-1][j1][j2][i2+1]&lefr[j1-1][i1][i2][j2+1]; } 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...