Submission #144098

#TimeUsernameProblemLanguageResultExecution timeMemory
144098KanonRectangles (IOI19_rect)C++14
0 / 100
44 ms49912 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define ordered_set tree<long long, null_type, greater<long long>, rb_tree_tag,tree_order_statistics_node_update> #define range(i, m, n) for(int i = m; i < n; i++) #define husk(i, m, n) for(int i = m; i > n; i--) long long count_rectangles(vector<vector<int>> a) { int m = a.front().size(); int n = a.size(); auto pos = [&] (vector<int> cur) { int s = cur.size(); vector<pair<int, int>> res; vector<int> st; range(i, 0, s) { while(st.size() && cur[st.back()] <= cur[i]) { if(st.back() < i - 1) res.emplace_back(st.back() + 1, i - 1); int b = st.back(); st.pop_back(); if(cur[b] == cur[i]) goto A; } if(st.size() && st.back() < i - 1) res.emplace_back(st.back() + 1, i - 1); A:; st.push_back(i); } return res; }; vector<vector<vector<pair<int, int>>>> hp; vector<vector<pair<int, int>>> cat; hp.resize(n); for(auto &i : hp) i.resize(m); cat.resize(m); for(auto &i : cat) i.resize(m, make_pair(-2, -2)); range(i, 0, n) { vector<pair<int, int>> foo = pos(a[i]); for(auto u : foo) { int l = u.first, r = u.second; pair<int, int> p = make_pair(l, i); if(cat[l][r].second == i - 1) { p.second = cat[l][r].first; cat[l][r].second = i; } else cat[l][r] = make_pair(i, i); hp[i][r].push_back(p); } } vector<vector<vector<pair<int, int>>>> vs; vs.resize(n); for(auto &i : vs) i.resize(m); vector<vector<pair<int, int>>> dog; dog.resize(n); for(auto &i : dog) i.resize(n, make_pair(-2, -2)); range(i, 0, m) { vector<int> fuck(n); range(j, 0, n) fuck[j] = a[j][i]; vector<pair<int, int>> foo = pos(fuck); for(auto u : foo) { int l = u.first, r = u.second; pair<int, int> p = make_pair(l, i); if(dog[l][r].second == i - 1) { p.second = cat[l][r].first; dog[l][r].second = i; } else dog[l][r] = make_pair(i, i); vs[r][i].push_back(p); } } long long res = 0; auto cnt = [&](vector<pair<int, int>> &x, vector<pair<int, int>> &y) { for(auto &i : y) { swap(i.first, i.second); } sort(y.begin(), y.end()); reverse(y.begin(), y.end()); reverse(x.begin(), x.end()); for(auto u : x) { for(auto v : y) { if(u.first <= v.first && v.second <= u.second) res++; } } return; ordered_set cur; auto it = x.begin(); int p = y.size() - 1; while(it != x.end()) { while(~p && y[p].first <= it->first) { cur.insert(y[p].second); p--; } res += cur.order_of_key(it->second - 1); it++; } }; range(i, 0, n) { range(j, 0, m) { cnt(hp[i][j], vs[i][j]); } } return res; }
#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...