Submission #1065503

#TimeUsernameProblemLanguageResultExecution timeMemory
1065503ewirlanRectangles (IOI19_rect)C++17
100 / 100
4024 ms873644 KiB
// #ifndef __SIZEOF_INT128__ #define __SIZEOF_INT128__ #endif #pragma GCC optimize("Ofast") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace chrono; using namespace __gnu_pbds; template <typename T> using oset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; #define rep(i, p, k) for(int i(p); i < (k); ++i) #define per(i, p, k) for(int i(p); i > (k); --i) #define sz(x) (int)(x).size() #define sc static_cast typedef long long ll; typedef long double ld; typedef unsigned int uint; typedef unsigned long long ull; typedef __int128_t lll; //#define int ll template <typename T = int> using par = std::pair <T, T>; #define fi first #define se second #define test int _number_of_tests(in()); while(_number_of_tests--) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define pb emplace_back struct Timer { string name{""}; time_point<high_resolution_clock> end, start{high_resolution_clock::now()}; duration<float, std::milli> dur; Timer() = default; Timer(string nm): name(nm) {} ~Timer() { end = high_resolution_clock::now(); dur= end - start; cout << "@" << name << "> " << dur.count() << " ms" << '\n'; } }; template <typename T = int> inline T in() { static T x; std::cin >> x; return x; } std::string yn(bool b) { if(b) return "YES\n"; else return "NO\n"; } template <typename F, typename S> std::ostream& operator<<(std::ostream& out, const std::pair <F, S>& par); template <typename T> std::ostream& operator<< (std::ostream& out, const std::vector <T>& wek) { for(const auto& i : wek)out << i << ' '; return out; } template <typename F, typename S> std::ostream& operator<<(std::ostream& out, const std::pair <F, S>& par) { out << '{'<<par.first<<", "<<par.second<<"}"; return out; } #define show(x) cerr << #x << " = " << x << '\n'; template <typename T> vector <int> ostw(T b, T e, bool r) { vector <int> o; vector <pair <int, int>> k{{1e9, -1}}; int j(0); for(auto i(b); i != e; ++i){ while(k.back().first < *i || (k.back().first == *i && !r))k.pop_back(); o.pb(k.back().second); k.pb(*i, j++); } return o; } constexpr int maxn = 2503, pol = 1<<12; array <array <int, maxn>, maxn> r, l, u, d; array <array <int, pol*2>, maxn> mr, ml, mu, md; template <typename T> void trurev(T b, T e, int n) { reverse(b, e); for(auto i(b); i != e; ++i)if(*i != -1)*i = n-1-*i; } struct rect{int x1, y1, x2, y2;}; bool operator<(rect a, rect b) { if(a.x1 != b.x1)return a.x1 < b.x1; if(a.y1 != b.y1)return a.y1 < b.y1; if(a.x2 != b.x2)return a.x2 < b.x2; return a.y2 < b.y2; } int maks(const array <int, pol*2>& tr, int a, int b) { a += pol; b += pol; int s(-1e9); while(a+1 != b){ if(a % 2 == 0)s = max(s, tr[a+1]); if(b % 2 == 1)s = max(s, tr[b-1]); a /= 2; b /= 2; } return s; } int mini(const array <int, pol*2>& tr, int a, int b) { a += pol; b += pol; int s(1e9); while(a+1 != b){ if(a % 2 == 0)s = min(s, tr[a+1]); if(b % 2 == 1)s = min(s, tr[b-1]); a /= 2; b /= 2; } return s; } ll count_rectangles(vector <vector <int>> a) { int n(sz(a)), m(sz(a[0])); rep(i, 0, n){ vector <int> dl(ostw(all(a[i]), 0)), dr(ostw(rall(a[i]), 0)), dml(ostw(all(a[i]), 1)), dmr(ostw(rall(a[i]), 1)); trurev(all(dr), m); trurev(all(dmr), m); rep(j, 0, m)l[i][j] = dl[j]; rep(j, 0, m)r[i][j] = dr[j]; rep(j, 0, m)ml[j][i+pol] = dml[j]; rep(j, 0, m)mr[j][i+pol] = dmr[j] == -1 ? 1e9 : dmr[j]; } rep(i, 0, m){ vector <int> v(n); rep(j, 0, n)v[j] = a[j][i]; vector <int> du(ostw(all(v), 0)), dd(ostw(rall(v), 0)), dmu(ostw(all(v), 1)), dmd(ostw(rall(v), 1)); trurev(all(dd), n); trurev(all(dmd), n); rep(j, 0, n)u[j][i] = du[j]; rep(j, 0, n)d[j][i] = dd[j]; rep(j, 0, n)mu[j][i+pol] = dmu[j]; rep(j, 0, n)md[j][i+pol] = dmd[j] == -1 ? 1e9 : dmd[j]; } rep(i, 0, n)per(j, pol-1, 0)mu[i][j] = max(mu[i][j*2], mu[i][j*2+1]); rep(i, 0, n)per(j, pol-1, 0)md[i][j] = min(md[i][j*2], md[i][j*2+1]); rep(i, 0, m)per(j, pol-1, 0)ml[i][j] = max(ml[i][j*2], ml[i][j*2+1]); rep(i, 0, m)per(j, pol-1, 0)mr[i][j] = min(mr[i][j*2], mr[i][j*2+1]); set <rect> S; rep(i, 0, n)rep(j, 0, m)if(~l[i][j] && ~u[i][j] && ~r[i][j] && ~d[i][j])S.insert({u[i][j], l[i][j], d[i][j], r[i][j]}); int o(0); for(auto [x1, y1, x2, y2]: S){ // cerr << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << " =/= "<< ' ' << maks(mu[x2], y1, y2) << ' ' << maks(ml[y2], x1, x2) << ' ' << mini(md[x1], y1, y2) << ' ' << mini(mr[y1], x1, x2) << '\n'; o += mini(md[x1], y1, y2) >= x2 && mini(mr[y1], x1, x2) >= y2 && maks(mu[x2], y1, y2) <= x1 && maks(ml[y2], x1, x2) <= y1; } return o; }
#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...