From ea8cd399e55a95706d6373a34e24a5efd648a39b Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Thu, 18 Nov 2021 20:24:13 +0800 Subject: [PATCH] =?UTF-8?q?#2279.=20=E3=80=8CSCOI2007=E3=80=8D=E9=99=8D?= =?UTF-8?q?=E9=9B=A8=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://loj.ac/s/1306934 --- LibreOJ/2279/2279.cpp | 109 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 LibreOJ/2279/2279.cpp diff --git a/LibreOJ/2279/2279.cpp b/LibreOJ/2279/2279.cpp new file mode 100644 index 00000000..900488b1 --- /dev/null +++ b/LibreOJ/2279/2279.cpp @@ -0,0 +1,109 @@ +#include + +using namespace std; + +struct node { + int l, r, max; + + node() + : l(0), r(0), max(0) {} + node(int _l, int _r) + : l(_l), r(_r), max(0) {} +} tr[50005 << 2]; + +int n, m, x, y, a[50005]; +map m1; + +void pushup(int u) { + tr[u].max = max(tr[u << 1].max, tr[u << 1 | 1].max); +} + +void build(int u, int l, int r) { + tr[u] = node(l, r); + if (l == r) { + tr[u].max = a[l]; + return; + } + int mid = l + r >> 1; + build(u << 1, l, mid); + build(u << 1 | 1, mid + 1, r); + pushup(u); +} + +int query(int u, int l, int r) { + if (l <= tr[u].l && tr[u].r <= r) { + return tr[u].max; + } + int mid = tr[u].l + tr[u].r >> 1; + int s = 0; + if (l <= mid) s = max(s, query(u << 1, l, r)); + if (r > mid) s = max(s, query(u << 1 | 1, l, r)); + return s; +} + +const char* solve(int x, int y) { + if (x == y) { + return "true"; + } else if (x > y) { + return "false"; + } + auto p1 = m1.lower_bound(x); + auto p2 = m1.lower_bound(y); + if (p2 == m1.end() || p2->first != y) { + if (p1 == m1.end() || p1->first != x) { + return "maybe"; + } + --p2; + if (p1->second + 1 > p2->second || query(1, p1->second + 1, p2->second) < a[p1->second]) { + return "maybe"; + } else { + return "false"; + } + } + if (p1 == m1.end()) { + return "maybe"; + } + if (p1->first == x) { + if (a[p1->second] < a[p2->second]) { + return "false"; + } + if (p1->second + 1 > p2->second - 1) { + return y - x == p2->second - p1->second ? "true" : "maybe"; + } else { + int mx = query(1, p1->second + 1, p2->second - 1); + if (mx >= a[p2->second]) { + return "false"; + } else { + return y - x == p2->second - p1->second ? "true" : "maybe"; + } + } + } else { + if (p1 == p2) { + return "maybe"; + } else { + int mx = query(1, p1->second, p2->second - 1); + if (mx >= a[p2->second]) { + return "false"; + } else { + return "maybe"; + } + } + } + return "failed"; +} + +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> x >> y; + m1[x] = i; + a[i] = y; + } + build(1, 1, n); + cin >> m; + for (int i = 0; i < m; i++) { + cin >> x >> y; + cout << solve(x, y) << endl; + } + return 0; +}