結果
| 問題 | No.2160 みたりのDominator |
| コンテスト | |
| ユーザー |
Kude
|
| 提出日時 | 2022-12-11 16:17:01 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 4,657 bytes |
| コンパイル時間 | 3,107 ms |
| コンパイル使用メモリ | 240,736 KB |
| 最終ジャッジ日時 | 2025-02-09 09:39:28 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 72 WA * 21 |
ソースコード
#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic pop
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
struct S {
int il, jl, ir, jr;
friend ostream& operator<<(ostream& os, const S& r) { return os << "(" << r.il << ", " << r.jl << ", " << r.ir << ", " << r.jr << ")"; }
};
} int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n1, n2, n3, m;
cin >> n1 >> n2 >> n3 >> m;
bool ok = true;
vector<P> e11, e22, e33, e12, e13, e23;
rep(_, m) {
int u, v;
cin >> u >> v;
if (u > v) swap(u, v);
if (v <= n1) {
e11.emplace_back(u, v);
} else if (v <= n1 + n2) {
if (u <= n1) e12.emplace_back(u, v - n1);
else e22.emplace_back(u - n1, v - n1);
} else if (v <= n1 + n2 + n3) {
if (u <= n1) e13.emplace_back(u, v - (n1 + n2));
else if (u <= n1 + n2) e23.emplace_back(u - n1, v - (n1 + n2));
else e33.emplace_back(u - (n1 + n2), v - (n1 + n2));
} else if (v == n1 + n2 + n3 + 1) {
if (u <= n1) e11.emplace_back(0, u);
else if (u <= n1 + n2) e22.emplace_back(0, u - n1);
else e33.emplace_back(0, u - (n1 + n2));
} else {
if (u <= n1) e11.emplace_back(u, n1 + 1);
else if (u <= n1 + n2) e22.emplace_back(u - n1, n2 + 1);
else if (u <= n1 + n2 + n3) e33.emplace_back(u - (n1 + n2), n3 + 1);
else ok = false;
}
}
if (!ok) {
cout << 0 << '\n';
return 0;
}
n1++, n2++, n3++;
sort(all(e12));
vector<S> st{{0, 0, -1, -1}};
for(auto [i, j]: e12) {
if (i == st.back().il) {
st.back().jl = j;
} else if (j <= st.back().jl) {
S r = st.back(); st.pop_back();
r.il = i;
while(!st.empty() && st.back().jl >= j) st.pop_back();
if (!st.empty()) chmin(st.back().jr, j);
st.emplace_back(r);
} else {
st.back().ir = i;
st.back().jr = j;
st.push_back(S{i, j, -1, -1});
}
}
st.back().ir = n1;
st.back().jr = n2;
constexpr int INF = 1001001001;
rep(_, 2) {
int bad_l = INF, bad_r = -INF;
for(auto [l, r]: e11) chmin(bad_l, l), chmax(bad_r, r);
vector<S> nst;
for(S r: st) {
if (r.il < bad_l) {
chmin(r.ir, bad_l);
} else if (r.ir <= bad_r) {
continue;
} else {
chmax(r.il, bad_r);
}
nst.emplace_back(r);
}
for(auto& [il, jl, ir, jr]: st) swap(il, jl), swap(ir, jr);
swap(e11, e22);
}
int sz = st.size();
VL acc(sz + 1);
rep(i, sz) {
auto [il, jl, ir, jr] = st[i];
acc[i+1] = acc[i] + ll(ir - il) * (jr - jl);
}
multiset<int, greater<int>> imn{-INF}, jmn{-INF};
multiset<int> imx{INF}, jmx{INF};
VVI ev1(n3 + 1), ev2(n3 + 1);
for(auto [i, k]: e13) {
imx.insert(i);
ev1[k].emplace_back(i);
}
for(auto [j, k]: e23) {
jmx.insert(j);
ev2[k].emplace_back(j);
}
int bad_l = INF, bad_r = -INF;
for(auto [l, r]: e33) chmin(bad_l, l), chmax(bad_r, r);
auto get_area = [](const S& r1, const S& r2) {
int il = max(r1.il, r2.il);
int jl = max(r1.jl, r2.jl);
int ir = min(r1.ir, r2.ir);
int jr = min(r1.jr, r2.jr);
if (il >= ir || jl >= jr) return 0LL;
return ll(ir - il) * (jr - jl);
};
ll ans = 0;
rep(z, n3) {
for(int i: ev1[z]) imx.erase(imx.find(i)), imn.insert(i);
for(int j: ev2[z]) jmx.erase(jmx.find(j)), jmn.insert(j);
if (bad_l <= z && z < bad_r) continue;
S r{*imn.begin(), *jmn.begin(), *imx.begin(), *jmx.begin()};
int from = max(lower_bound(all(st), r, [](const S& x, const S& y) { return x.il < y.il; }) - st.begin(),
lower_bound(all(st), r, [](const S& x, const S& y) { return x.jl < y.jl; }) - st.begin());
int to = min(upper_bound(all(st), r, [](const S& x, const S& y) { return x.ir < y.ir; }) - st.begin(),
upper_bound(all(st), r, [](const S& x, const S& y) { return x.jr < y.jr; }) - st.begin());
if (from < to) ans += acc[to] - acc[from];
if (from) ans += get_area(st[from - 1], r);
if (to < sz && to != from - 1) ans += get_area(st[to], r);
}
cout << ans << '\n';
}
Kude