제출 #144027

#제출 시각아이디문제언어결과실행 시간메모리
144027KanonRectangles (IOI19_rect)C++14
72 / 100
3163 ms1048580 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<int, int>>>> hp, vs; hp.resize(n); for(auto &i : hp) i.resize(m); vs.resize(n); for(auto &i : vs) 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<int, int> 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(i, 0, m) { vector<int> ss(n); range(j, 0, n) ss[j] = a[j][i]; vector<pair<int, int>> foo = pos(ss); for(auto u : foo) { int l = u.first, r = u.second; pair<int, int> 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); } } long long res = 0; auto cnt = [&](set<pair<int, int>> &x, set<pair<int, int>> &y) { vector<pair<int, int>> sy; for(auto i : y) { swap(i.first, i.second); sy.push_back(i); } sort(sy.begin(), sy.end()); reverse(sy.begin(), sy.end()); ordered_set cur; auto it = x.begin(); int p = sy.size() - 1; while(it != x.end()) { while(~p && sy[p].first <= it->first) { cur.insert(sy[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...