이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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) {
for(auto u : x) {
for(auto v : y) {
if(u.second <= v.first && v.second <= u.first) res++;
}
}
return;
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.end();
int p = sy.size() - 1;
while(it != x.begin()) {
it--;
while(~p && sy[p].first <= it->first) {
cur.insert(sy[p].second);
p--;
}
res += cur.order_of_key(it->second - 1);
}
};
range(i, 0, n) {
range(j, 0, m) {
cnt(hp[i][j], vs[i][j]);
}
}
return res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |