QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#611637 | #8939. Permutation | UESTC_OldEastWest | WA | 1837ms | 331436kb | C++17 | 2.2kb | 2024-10-04 21:52:03 | 2024-10-04 21:52:05 |
Judging History
answer
#include <bits/stdc++.h>
const int N = 1e6 + 5;
const int M = 31;
const int INF = 1e9;
const double eps = 1e-8;
std::vector<std::vector<int> > dp, f;
void prep() {
dp = f = std::vector<std::vector<int> > (N, std::vector<int> (M));
std::function<int(int, int)> DFS = [&](int n, int m) {
if (n <= 2) return 0;
if (m <= -1) return INF;
if (dp[n][m]) return dp[n][m];
dp[n][m] = INF;
int mid = n - n / 3;
for (int i = std::max(1, mid - 30); i < std::min(n, mid + 30); ++i) {
int new_val = std::max(DFS(i, m - 1), DFS(n - i, m - 2) + n - i) + i;
if (new_val < dp[n][m]) f[n][m] = i, dp[n][m] = new_val;
}
return dp[n][m];
};
for (int i = 2; i < N; ++i) {
int k = int(1.5 * log(i) / log(2) + 1.0);
for (int j = std::max(0, k - 2); j < k; ++j) DFS(i, j);
if (DFS(i, k) > 2 * i) std::cout << '!';
// if (i % 1000 == 0) std::cout << i << ' ' << DFS(i, k) << '\n';
}
// std::cout << "Finished." << std::endl;
}
void charming() {
int n; std::cin >> n;
std::function<int(int, int)> Send = [&](int l, int r) {
if (l == r) return -1;
std::cout << "? " << l << ' ' << r << '\n';
std::cout.flush();
int rcv; std::cin >> rcv;
return rcv;
};
std::function<void(int)> Answer = [&](int x) {
std::cout << "! " << x << '\n';
std::cout.flush();
};
int remain = int(1.5 * (log(n) / log(2)) + 1.0 + eps);
// std::cout << remain << '\n';
int l = 1, r = n, p = -1;
while (l < r) {
if (p == -1) p = Send(l, r), --remain;
if (l + 1 == r) {
if (p == l) ++l;
break;
}
int ask_len = f[r - l + 1][remain];
if (l + ask_len - 1 >= p) {
int q = Send(l, l + ask_len - 1); --remain;
if (q == p) r = l + ask_len - 1;
else l = l + ask_len, p = -1;
}
else {
int q = Send(r - ask_len + 1, r); --remain;
if (q == p) l = r - ask_len + 1;
else r = r - ask_len, p = -1;
}
}
Answer(l);
}
signed main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
prep();
int t; std::cin >> t;
while (t--) charming();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1819ms
memory: 331140kb
input:
3 5 3 2 5 6 6 3 1 4 3 3
output:
? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 6 ? 3 6 ? 1 2 ! 2 ? 1 4 ? 3 4 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: 0
Accepted
time: 1837ms
memory: 331436kb
input:
10000 10 2 2 2 1 3 10 10 10 7 5 10 5 1 10 9 8 10 4 4 4 4 10 10 6 3 4 2 10 3 3 3 4 2 10 1 5 9 10 7 10 1 3 8 8 10 2 4 9 9 10 3 3 3 3 10 4 1 7 8 9 10 8 7 1 2 4 10 4 1 9 9 10 7 7 7 8 6 10 5 1 7 8 10 10 8 8 6 9 10 2 2 1 5 10 6 4 10 10 10 1 3 8 8 10 7 9 4 4 10 7 8 4 4 10 3 4 7 8 10 10 4 4 1 6 10 8 7 4 3 2...
output:
? 1 10 ? 1 6 ? 1 4 ? 1 2 ? 3 4 ! 4 ? 1 10 ? 5 10 ? 7 10 ? 5 6 ! 6 ? 1 10 ? 1 6 ? 7 10 ? 9 10 ? 7 8 ! 7 ? 1 10 ? 1 6 ? 1 4 ? 3 4 ! 3 ? 1 10 ? 5 10 ? 1 4 ? 3 4 ? 1 2 ! 1 ? 1 10 ? 1 6 ? 1 4 ? 3 4 ? 1 2 ! 1 ? 1 10 ? 1 6 ? 7 10 ? 9 10 ? 7 8 ! 8 ? 1 10 ? 1 6 ? 7 10 ? 7 8 ! 7 ? 1 10 ? 1 6 ? 7 10 ? 9 10 ! 1...
result:
ok Correct (10000 test cases)
Test #3:
score: -100
Wrong Answer
time: 1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