From b5c8feb3e95bfd305e3a84e7fb53de0ddf4b2440 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Fri, 18 Nov 2022 22:20:21 +0800 Subject: [PATCH] #3633. Pair http://www.nfls.com.cn:20035/submission/592121 --- NFLSOJ/0/3633/3633.cpp | 90 +++++++++++++++++++++++++++++++++ NFLSOJ/0/3633/samples/pair1.ans | 3 ++ NFLSOJ/0/3633/samples/pair1.in | 3 ++ NFLSOJ/0/3633/samples/pair2.ans | 3 ++ NFLSOJ/0/3633/samples/pair2.in | 3 ++ 5 files changed, 102 insertions(+) create mode 100644 NFLSOJ/0/3633/3633.cpp create mode 100644 NFLSOJ/0/3633/samples/pair1.ans create mode 100644 NFLSOJ/0/3633/samples/pair1.in create mode 100644 NFLSOJ/0/3633/samples/pair2.ans create mode 100644 NFLSOJ/0/3633/samples/pair2.in diff --git a/NFLSOJ/0/3633/3633.cpp b/NFLSOJ/0/3633/3633.cpp new file mode 100644 index 00000000..b68c539e --- /dev/null +++ b/NFLSOJ/0/3633/3633.cpp @@ -0,0 +1,90 @@ +// #include +#include +#include +#include +#include + +// using std::cin; +// using std::cout; +std::ifstream cin("pair.in"); +std::ofstream cout("pair.out"); +const char endl = '\n'; + +const int N = 2e5 + 5, + M = (1 << 8) + 5; + +int n, q, max_pre[M][N], max_suf[M][N], max_val[M][M][(1 << 9) + 5][2]; +std::pair a[N]; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n; + + for (int i = 1; i <= n; i++) { + cin >> a[i].first >> a[i].second; + } + + std::sort(a + 1, a + 1 + n, [&](const auto &lhs, const auto &rhs) -> bool { return (lhs.first & 0x1ff) < (rhs.first & 0x1ff); }); + + for (int i = 0; i < 1 << 8; i++) { + max_pre[i][0] = max_suf[i][n + 1] = 0; + + for (int j = 1; j <= n; j++) { + max_pre[i][j] = std::max(max_pre[i][j - 1], (i + (a[j].first >> 9)) ^ (a[j].second >> 9)); + } + + for (int j = n; j; j--) { + max_suf[i][j] = std::max(max_suf[i][j + 1], (i + (a[j].first >> 9)) ^ (a[j].second >> 9)); + } + } + + memset(max_val, 0xff, sizeof(max_val)); + + for (int i = 1; i <= n; i++) { + for (int j = 0; j <= 0x1ff; j++) { + max_val[a[i].first >> 9][a[i].second >> 9][j][j + (a[i].first & 0x1ff) >= 0x200] = std::max( + max_val[a[i].first >> 9][a[i].second >> 9][j][j + (a[i].first & 0x1ff) >= 0x200], + ((j + a[i].first) ^ a[i].second) & 0x1ff); + } + } + + cin >> q; + + while (q--) { + int t, l = 1, r = n, res = 1; + + cin >> t; + + while (l <= r) { + int mid = l + r >> 1; + + if ((t & 0x1ff) + (a[mid].first & 0x1ff) < 0x200) { + l = mid + 1; + res = mid; + } else { + r = mid - 1; + } + } + + int high = std::max(max_pre[t >> 9][res], max_suf[(t >> 9) + 1][res + 1]), + low = -1; + + for (int i = 0; i <= 0xff; i++) { + int j = (high ^ i) - (t >> 9); + + if (0 <= j && j <= 0xff) { + low = std::max(low, max_val[j][i][t & 0x1ff][0]); + } + + if (0 <= j - 1 && j - 1 <= 0xff) { + low = std::max(low, max_val[j - 1][i][t & 0x1ff][1]); + } + } + + cout << (high << 9 | low) << endl; + } + + return 0; +} diff --git a/NFLSOJ/0/3633/samples/pair1.ans b/NFLSOJ/0/3633/samples/pair1.ans new file mode 100644 index 00000000..52d25e36 --- /dev/null +++ b/NFLSOJ/0/3633/samples/pair1.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9a7f2139ccb2474158ed193cd6ff87a7f6535e17b66cf26298d8d41db4ccb2ad +size 15 diff --git a/NFLSOJ/0/3633/samples/pair1.in b/NFLSOJ/0/3633/samples/pair1.in new file mode 100644 index 00000000..9aac58d2 --- /dev/null +++ b/NFLSOJ/0/3633/samples/pair1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8afe64a1f86e2e88a7fbf05c42823f3372bdc8bacca72b70f7f3e2e0a1aafd81 +size 35 diff --git a/NFLSOJ/0/3633/samples/pair2.ans b/NFLSOJ/0/3633/samples/pair2.ans new file mode 100644 index 00000000..2eea3b18 --- /dev/null +++ b/NFLSOJ/0/3633/samples/pair2.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:71339619effa875236c553e0d17ef9d7019470616ce03e92a0fb05857bf8c0ac +size 1600000 diff --git a/NFLSOJ/0/3633/samples/pair2.in b/NFLSOJ/0/3633/samples/pair2.in new file mode 100644 index 00000000..c2604290 --- /dev/null +++ b/NFLSOJ/0/3633/samples/pair2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2d76685086a53ae9bd2ece7b83b9d09f41317bf35751b788d5cd24110bbcf689 +size 3533178