Submission #144034

#TimeUsernameProblemLanguageResultExecution timeMemory
144034KanonRectangles (IOI19_rect)C++14
72 / 100
5145 ms999284 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<set<pair<short, short>>>> hp; hp.resize(n); for(auto &i : hp) i.resize(m); vector<vector<vector<pair<short, short>>>> pp; pp.resize(n); for(auto &i : pp) i.resize(m); range(i, 0, n) { vector<pair<int, int>> foo = pos(a[i]); for(auto u : foo) { int l = u.first, r = u.second; pair<short, short> p = make_pair(l, i); if(i && hp[i - 1][r].lower_bound(make_pair(l, -1))->first == l) p.second = hp[i - 1][r].lower_bound(make_pair(l, -1))->second; hp[i][r].insert(p); } range(r, 0, m) for(auto j : hp[i][r]) pp[i][r].push_back(j); if(i >= 2) hp[i - 2].clear(); } hp.clear(); vector<vector<set<pair<short, short>>>> vs; vs.resize(n); for(auto &i : vs) i.resize(m); vector<vector<vector<pair<short, short>>>> ss; ss.resize(n); for(auto &i : ss) i.resize(m); 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<short, short> p = make_pair(l, i); if(i && vs[r][i - 1].lower_bound(make_pair(l, -1))->first == l) p.second = vs[r][i - 1].lower_bound(make_pair(l, -1))->second; vs[r][i].insert(p); } range(r, 0, n) for(auto j : vs[r][i]) ss[r][i].push_back(j); } vs.clear(); long long res = 0; auto cnt = [&](vector<pair<short, short>> &x, vector<pair<short, short>> &y) { for(auto &i : y) { swap(i.first, i.second); } sort(y.begin(), y.end()); reverse(y.begin(), y.end()); 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(pp[i][j], ss[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...