QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#611638 | #8939. Permutation | UESTC_OldEastWest | WA | 1845ms | 331484kb | C++17 | 2.2kb | 2024-10-04 21:52:45 | 2024-10-04 21:52:46 |
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 <= 1) 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: 1661ms
memory: 331336kb
input:
3 5 3 2 5 6 6 5 3 3 4 3 3
output:
? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 6 ? 4 6 ? 1 3 ? 2 3 ! 2 ? 1 4 ? 3 4 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: 0
Accepted
time: 1746ms
memory: 331356kb
input:
10000 10 2 2 3 5 5 10 10 10 8 5 5 10 5 1 10 9 8 10 4 4 6 2 1 10 10 6 3 4 2 10 3 3 3 2 10 1 5 9 10 7 10 1 3 8 8 10 2 4 9 9 10 3 3 1 5 5 10 4 1 7 8 9 10 8 7 1 2 4 10 4 1 9 9 10 7 7 7 6 10 5 1 7 8 10 10 8 8 8 9 10 2 2 1 5 4 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 4 4 10 8 7 4...
output:
? 1 10 ? 1 6 ? 1 3 ? 4 6 ? 4 5 ! 4 ? 1 10 ? 5 10 ? 8 10 ? 5 7 ? 5 6 ! 6 ? 1 10 ? 1 6 ? 7 10 ? 9 10 ? 7 8 ! 7 ? 1 10 ? 1 6 ? 4 6 ? 1 3 ? 1 2 ! 3 ? 1 10 ? 5 10 ? 1 4 ? 3 4 ? 1 2 ! 1 ? 1 10 ? 1 6 ? 1 3 ? 2 3 ! 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 ...
result:
ok Correct (10000 test cases)
Test #3:
score: 0
Accepted
time: 1790ms
memory: 331432kb
input:
10000 3 1 2 11 5 5 5 4 2 2 19 3 3 4 11 11 11 7 5 7 1 2 3 3 3 19 6 6 6 5 1 2 2 2 15 11 11 11 11 10 14 1 1 1 3 5 16 4 4 4 4 5 3 3 2 19 13 17 5 5 5 4 2 2 4 1 2 3 7 2 2 2 3 2 2 17 1 1 1 2 4 4 14 9 9 9 7 11 20 9 9 9 6 11 10 6 4 4 5 18 7 7 7 7 6 8 8 8 6 5 8 6 6 6 5 16 10 10 10 10 10 6 1 3 6 5 10 3 3 1 4 4...
output:
? 1 3 ? 1 2 ! 3 ? 1 11 ? 1 6 ? 4 6 ? 4 5 ! 6 ? 1 2 ! 1 ? 1 19 ? 1 11 ? 1 6 ? 7 11 ? 9 11 ? 10 11 ! 10 ? 1 7 ? 4 7 ? 1 3 ? 1 2 ! 3 ? 1 3 ? 2 3 ! 2 ? 1 19 ? 1 11 ? 1 6 ? 4 6 ? 1 3 ? 1 2 ! 3 ? 1 2 ! 1 ? 1 15 ? 7 15 ? 7 11 ? 9 11 ? 10 11 ! 9 ? 1 14 ? 1 8 ? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 16 ? 1 10 ? 1 6 ? 4 6 ?...
result:
ok Correct (10000 test cases)
Test #4:
score: 0
Accepted
time: 1815ms
memory: 331436kb
input:
10000 47 23 23 24 11 9 2 1 5 14 8 2 9 9 9 25 6 6 4 13 13 13 7 4 2 6 6 9 2 2 2 2 27 27 27 27 27 26 24 23 21 7 7 7 7 6 5 43 41 21 7 7 8 4 3 1 22 6 12 14 17 20 19 21 34 29 29 25 17 17 18 14 42 20 20 20 20 20 20 19 47 21 21 21 21 21 20 19 19 41 25 11 30 33 36 36 36 19 17 17 16 9 9 10 21 14 14 14 14 14 1...
output:
? 1 47 ? 1 29 ? 12 29 ? 1 11 ? 6 11 ? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 14 ? 1 8 ? 9 14 ? 9 11 ? 9 10 ! 10 ? 1 25 ? 1 15 ? 1 9 ? 10 15 ? 13 15 ? 13 14 ! 14 ? 1 7 ? 1 4 ? 5 7 ? 5 6 ! 5 ? 1 9 ? 1 5 ? 1 3 ? 1 2 ! 1 ? 1 27 ? 12 27 ? 18 27 ? 22 27 ? 25 27 ? 22 24 ? 23 24 ! 22 ? 1 21 ? 1 13 ? 1 8 ? 4 8 ? 6 8 ? 4 5 ...
result:
ok Correct (10000 test cases)
Test #5:
score: 0
Accepted
time: 1845ms
memory: 331332kb
input:
10000 100 47 61 93 96 71 71 71 71 71 9 2 2 2 1 53 46 35 6 6 6 6 6 6 33 3 16 31 31 31 29 32 82 60 41 29 29 29 28 23 24 26 88 39 8 59 59 59 59 59 59 59 71 24 29 59 49 65 65 64 61 61 92 52 45 88 88 88 88 85 91 91 24 11 11 9 5 5 5 66 51 51 45 29 28 39 38 40 40 92 43 43 50 20 20 20 20 20 19 48 1 1 1 1 5 ...
output:
? 1 100 ? 1 61 ? 62 100 ? 77 100 ? 62 76 ? 68 76 ? 68 72 ? 70 72 ? 70 71 ! 70 ? 1 9 ? 1 5 ? 1 3 ? 1 2 ! 3 ? 1 53 ? 22 53 ? 1 21 ? 1 13 ? 1 8 ? 4 8 ? 4 6 ? 5 6 ! 5 ? 1 33 ? 1 20 ? 21 33 ? 26 33 ? 29 33 ? 29 31 ? 32 33 ! 33 ? 1 82 ? 33 82 ? 1 32 ? 14 32 ? 22 32 ? 27 32 ? 22 26 ? 22 24 ? 25 26 ! 25 ? 1...
result:
ok Correct (10000 test cases)
Test #6:
score: 0
Accepted
time: 1841ms
memory: 331392kb
input:
10000 50 10 10 10 10 6 2 3 5 50 11 11 9 31 26 23 23 22 50 44 44 40 20 20 21 26 25 50 24 14 45 45 40 49 48 46 50 50 50 50 50 50 49 47 47 50 36 23 17 17 18 12 11 10 50 29 29 20 3 3 3 3 50 30 30 22 1 1 1 2 4 50 25 25 25 25 21 30 31 27 50 18 20 49 47 37 37 35 39 50 9 9 9 5 17 19 14 13 50 26 26 26 28 17 ...
output:
? 1 50 ? 1 31 ? 1 19 ? 1 11 ? 6 11 ? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 50 ? 1 31 ? 1 19 ? 20 31 ? 25 31 ? 20 24 ? 22 24 ? 22 23 ! 24 ? 1 50 ? 20 50 ? 32 50 ? 20 31 ? 20 26 ? 20 23 ? 24 26 ? 25 26 ! 24 ? 1 50 ? 1 31 ? 32 50 ? 40 50 ? 40 45 ? 46 50 ? 48 50 ? 46 47 ! 47 ? 1 50 ? 20 50 ? 32 50 ? 40 50 ? 45 50 ? 4...
result:
ok Correct (10000 test cases)
Test #7:
score: 0
Accepted
time: 1828ms
memory: 331432kb
input:
10000 100 76 49 35 34 5 3 11 11 11 100 29 29 29 29 29 29 30 26 26 100 64 64 69 88 88 86 78 77 80 81 100 51 57 98 98 92 79 79 77 81 80 100 44 44 50 13 13 13 12 9 9 100 64 92 22 19 27 25 35 36 39 39 100 93 93 86 56 59 40 44 49 48 47 100 37 2 97 81 76 76 74 68 68 100 76 76 58 94 95 80 79 86 85 83 100 3...
output:
? 1 100 ? 40 100 ? 1 39 ? 16 39 ? 1 15 ? 1 9 ? 10 15 ? 10 12 ? 10 11 ! 10 ? 1 100 ? 1 61 ? 1 37 ? 15 37 ? 24 37 ? 24 31 ? 27 31 ? 24 26 ? 25 26 ! 25 ? 1 100 ? 40 100 ? 40 76 ? 77 100 ? 77 90 ? 83 90 ? 77 82 ? 77 79 ? 80 82 ? 80 81 ! 82 ? 1 100 ? 1 61 ? 62 100 ? 77 100 ? 87 100 ? 77 86 ? 77 82 ? 77 7...
result:
ok Correct (10000 test cases)
Test #8:
score: 0
Accepted
time: 1699ms
memory: 331484kb
input:
1000 1000 475 426 728 728 747 831 831 828 841 841 841 844 847 847 1000 278 17 974 811 770 766 679 689 652 655 639 640 645 645 1000 75 128 871 985 644 686 773 749 732 730 737 737 739 741 1000 239 239 45 577 607 432 442 458 458 458 459 462 463 465 1000 978 978 978 978 978 978 997 914 914 920 923 923 9...
output:
? 1 1000 ? 1 637 ? 638 1000 ? 638 861 ? 638 775 ? 776 861 ? 809 861 ? 809 840 ? 841 861 ? 841 853 ? 841 848 ? 841 845 ? 846 848 ? 846 847 ! 846 ? 1 1000 ? 1 637 ? 638 1000 ? 777 1000 ? 638 776 ? 691 776 ? 638 690 ? 659 690 ? 638 658 ? 646 658 ? 638 645 ? 638 642 ? 643 645 ? 644 645 ! 644 ? 1 1000 ? ...
result:
ok Correct (1000 test cases)
Test #9:
score: 0
Accepted
time: 1727ms
memory: 331480kb
input:
1017 272 246 111 27 52 73 73 73 73 73 71 75 114 105 91 2 2 2 2 2 2 2 910 173 173 173 173 127 14 14 29 35 37 51 51 52 48 726 229 229 229 201 63 63 28 17 17 13 24 24 24 861 315 104 671 671 688 593 593 593 593 586 597 597 598 596 1984 133 133 133 406 571 571 583 704 701 650 650 650 650 651 647 646 1145...
output:
? 1 272 ? 105 272 ? 1 104 ? 1 64 ? 65 104 ? 65 88 ? 65 78 ? 71 78 ? 71 75 ? 71 73 ? 74 75 ! 74 ? 1 114 ? 45 114 ? 1 44 ? 1 27 ? 1 16 ? 1 10 ? 1 6 ? 1 3 ? 1 2 ! 1 ? 1 910 ? 1 577 ? 1 356 ? 1 220 ? 85 220 ? 1 84 ? 1 52 ? 1 32 ? 33 52 ? 33 44 ? 45 52 ? 48 52 ? 50 52 ? 48 49 ! 49 ? 1 726 ? 1 454 ? 1 280...
result:
ok Correct (1017 test cases)
Test #10:
score: -100
Wrong Answer
time: 1649ms
memory: 331384kb
input:
10 100000 3893
output:
? 1 100000 ? 100001 100000
result:
wrong answer Integer 100001 violates the range [1, 99999] (test case 1)