QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#593305 | #8939. Permutation | lwm7708 | WA | 69ms | 3764kb | C++17 | 2.7kb | 2024-09-27 13:12:13 | 2024-09-27 13:12:19 |
Judging History
answer
#include <algorithm>
#include <cstdint>
#include <ios>
#include <iostream>
#include <ostream>
#include <utility>
#include <vector>
template <typename F>
class y_combinator {
private:
F f;
public:
explicit y_combinator(F&& f) : f(f) {}
template <typename... Args>
decltype(auto) operator()(Args&&... args) const {
return f(*this, std::forward<Args>(args)...);
}
};
template <typename F>
y_combinator(F) -> y_combinator<F>;
void solve() {
std::int32_t n;
std::cin >> n;
std::vector<std::int32_t> dp(n + 1);
std::vector<std::int32_t> opt(n + 1);
const auto qry = [](std::int32_t l, std::int32_t r) -> std::int32_t {
std::cout << "? " << l + 1 << ' ' << r << '\n' << std::flush;
std::int32_t idx;
std::cin >> idx;
--idx;
return idx;
};
dp[1] = -1;
for (std::int32_t i = 3; i <= n; ++i) {
std::int32_t& c_opt = opt[i];
c_opt = opt[i - 1];
dp[i] = std::max(dp[c_opt] + 1, dp[i - c_opt] + 2);
while (c_opt + 1 < i) {
const std::int32_t c_dp = std::max(dp[c_opt + 1] + 1, dp[i - (c_opt + 1)] + 2);
if (c_dp > dp[i]) {
break;
}
dp[i] = c_dp;
++c_opt;
}
}
y_combinator(
[&](auto self, std::int32_t idx_l, std::int32_t idx_r, std::int32_t p_idx) -> void {
const std::int32_t len = idx_r - idx_l;
if (len == 1) {
std::cout << "! " << idx_l + 1 << '\n' << std::flush;
return;
}
if (p_idx == -1) {
p_idx = qry(idx_l, idx_r);
}
if (len == 2) {
std::cout << "! " << (idx_l ^ (idx_l + 1) ^ p_idx) + 1 << '\n' << std::flush;
return;
}
if (p_idx < idx_l + opt[len]) {
const std::int32_t idx_m = idx_l + opt[len];
if (qry(idx_l, idx_m) == p_idx) {
self(idx_l, idx_m, p_idx);
} else {
self(idx_m, idx_r, -1);
}
} else {
const std::int32_t idx_m = idx_r - opt[len];
if (qry(idx_m, idx_r) == p_idx) {
self(idx_m, idx_r, p_idx);
} else {
self(idx_l, idx_m, -1);
}
}
}
)(0, n, -1);
}
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::int32_t t;
std::cin >> t;
for (std::int32_t i = 0; i < t; ++i) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3640kb
input:
3 5 3 2 5 6 6 6 5 3 4 3 2
output:
? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 6 ? 2 6 ? 4 6 ? 2 3 ! 2 ? 1 4 ? 1 3 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: 0
Accepted
time: 69ms
memory: 3560kb
input:
10000 10 2 2 2 3 5 10 10 10 10 8 7 10 5 5 1 6 6 10 4 4 4 4 4 10 10 3 2 10 3 3 3 3 2 10 1 1 5 6 7 10 1 1 3 8 8 10 2 4 9 10 3 3 3 1 5 10 4 7 9 10 8 8 7 1 2 10 4 1 9 10 7 7 7 8 4 10 5 1 10 10 8 6 9 10 2 2 1 7 7 10 6 4 10 10 1 1 3 8 8 10 7 7 5 1 2 10 7 7 4 1 2 10 3 4 10 10 4 4 4 4 3 10 8 8 7 2 2 10 8 8 ...
output:
? 1 10 ? 1 8 ? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 10 ? 3 10 ? 6 10 ? 8 10 ? 6 7 ! 6 ? 1 10 ? 1 8 ? 1 5 ? 6 8 ? 6 7 ! 7 ? 1 10 ? 1 8 ? 1 5 ? 3 5 ? 3 4 ! 3 ? 1 10 ? 3 10 ? 1 2 ! 1 ? 1 10 ? 1 8 ? 1 5 ? 1 3 ? 2 3 ! 1 ? 1 10 ? 1 8 ? 1 5 ? 6 8 ? 6 7 ! 8 ? 1 10 ? 1 8 ? 1 5 ? 6 8 ? 7 8 ! 7 ? 1 10 ? 1 8 ? 9 10 !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