QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#618441 | #8939. Permutation | Legend_dy | WA | 136ms | 3784kb | C++20 | 2.0kb | 2024-10-06 22:08:49 | 2024-10-06 22:08:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int p[1000005];
int querycnt = 0, length = 0;
int force(int l, int r) {
querycnt++;
length += r - l + 1;
int mx = 0, se = 0;
for (int i = l; i <= r; i++) {
if (p[i] >= p[mx]) {
se = mx;
mx = i;
}else if (p[i] > p[se]) {
se = i;
}
}
return se;
}
int ask(int l, int r) {
if (l == r) return -1;
// return force(l, r);
cout << "? " << l << ' ' << r << endl;
int p;
cin >> p;
return p;
}
constexpr double kkk = 0.58;
void solve() {
int n;
cin >> n;
int l = 1, r = n;
// iota(p + 1, p + n + 1, 1);
// random_shuffle(p + 1, p + n + 1);
// int pos;
// for (int i = 1; i <= n; i++) if (p[i] == n) pos = i;
int se = ask(1, n);
while (l < r) {
int m = (l + r) / 2;
int mid;
if (se <= m) {
mid = ceil(l + kkk * double(r - l));
int nse = ask(l, mid - 1);
if (nse == se) {
r = mid - 1;
}else {
l = mid;
se = ask(l, r);
}
}else {
mid = floor(r - kkk * double(r - l));
int nse = ask(mid + 1, r);
if (nse == se) {
l = mid + 1;
}else {
r = mid;
se = ask(l, r);
}
}
}
// cerr << pos << ' ' << l << "\n";
// cerr << ceil(1.5 * log2(n)) << ' ' << querycnt << '\n';
// cerr << 3 * n << ' ' << length << '\n';
cout << "! " << l << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
srand(time(0));
int tt;
cin >> tt;
while (tt--) {
solve();
}
// int l = 1, r = n;
// int ans = 0;
// while (l < r) {
// int m = (l * 65 + r * 35) / 100;
// ans += r - l + 1;
// l = m + 1;
// }
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3704kb
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: 44ms
memory: 3772kb
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 6 5 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...
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: 34ms
memory: 3784kb
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 1 8 9 7 3 3 2 19 13 17 5 6 2 1 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 5 9 9 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...
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 9 ? 1 5 ? 6 9 ? ...
result:
ok Correct (10000 test cases)
Test #4:
score: 0
Accepted
time: 98ms
memory: 3644kb
input:
10000 47 23 23 24 11 9 2 1 5 14 8 8 8 7 11 25 6 6 4 13 13 12 7 4 2 6 6 9 2 2 2 2 27 27 27 27 24 19 20 21 21 7 7 6 5 5 5 43 41 21 7 7 8 4 3 1 22 6 12 14 17 20 19 21 34 29 29 25 17 17 17 16 42 20 20 20 20 20 19 17 47 21 21 21 19 15 12 16 17 41 25 25 30 33 33 34 36 35 19 17 17 16 9 9 10 21 14 14 14 15 ...
output:
? 1 47 ? 1 27 ? 12 27 ? 1 11 ? 6 11 ? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 14 ? 7 14 ? 7 11 ? 7 9 ? 10 11 ! 10 ? 1 25 ? 1 14 ? 1 8 ? 9 14 ? 12 14 ? 12 13 ! 14 ? 1 7 ? 1 4 ? 5 7 ? 5 6 ! 5 ? 1 9 ? 1 5 ? 1 3 ? 1 2 ! 1 ? 1 27 ? 12 27 ? 19 27 ? 23 27 ? 19 22 ? 19 20 ? 21 22 ! 22 ? 1 21 ? 1 12 ? 6 12 ? 1 5 ? 3 5 ? 4 5...
result:
ok Correct (10000 test cases)
Test #5:
score: 0
Accepted
time: 108ms
memory: 3780kb
input:
10000 100 47 5 61 61 61 62 71 71 71 9 2 2 2 1 53 46 35 6 6 6 6 7 4 33 3 16 31 31 31 29 32 82 60 41 29 29 29 29 28 26 26 88 39 8 59 59 59 59 59 60 57 71 24 29 59 59 59 60 64 63 61 92 52 52 45 88 88 88 89 91 91 24 11 11 9 5 5 5 66 51 51 45 29 35 39 39 38 40 92 43 43 50 20 20 20 21 17 16 48 1 1 1 1 5 9...
output:
? 1 100 ? 1 58 ? 59 100 ? 59 82 ? 59 72 ? 59 66 ? 67 72 ? 70 72 ? 70 71 ! 70 ? 1 9 ? 1 5 ? 1 3 ? 1 2 ! 3 ? 1 53 ? 23 53 ? 1 22 ? 1 13 ? 1 7 ? 4 7 ? 6 7 ? 4 5 ! 5 ? 1 33 ? 1 19 ? 20 33 ? 26 33 ? 29 33 ? 29 31 ? 32 33 ! 33 ? 1 82 ? 36 82 ? 1 35 ? 16 35 ? 24 35 ? 24 30 ? 27 30 ? 24 26 ? 25 26 ! 25 ? 1 ...
result:
ok Correct (10000 test cases)
Test #6:
score: 0
Accepted
time: 99ms
memory: 3640kb
input:
10000 50 10 10 10 14 2 2 1 3 50 11 11 9 18 18 21 23 22 50 44 44 40 26 26 27 23 22 50 24 14 45 45 45 45 44 46 50 50 50 50 50 50 49 47 47 50 36 23 17 18 5 1 6 7 8 50 29 36 20 13 3 3 1 5 50 30 42 16 21 1 1 1 2 50 25 25 25 25 25 26 29 29 50 18 20 49 47 30 34 37 37 50 9 9 9 5 17 14 13 13 50 26 43 17 17 1...
output:
? 1 50 ? 1 29 ? 1 17 ? 8 17 ? 1 7 ? 1 4 ? 1 2 ? 3 4 ! 4 ? 1 50 ? 1 29 ? 1 17 ? 18 29 ? 18 24 ? 18 21 ? 22 24 ? 22 23 ! 24 ? 1 50 ? 22 50 ? 34 50 ? 22 33 ? 22 28 ? 25 28 ? 22 24 ? 22 23 ! 24 ? 1 50 ? 1 29 ? 30 50 ? 39 50 ? 44 50 ? 44 47 ? 44 45 ? 46 47 ! 47 ? 1 50 ? 22 50 ? 34 50 ? 41 50 ? 45 50 ? 48...
result:
ok Correct (10000 test cases)
Test #7:
score: 0
Accepted
time: 136ms
memory: 3700kb
input:
10000 100 76 49 35 41 5 5 3 9 9 100 29 29 29 29 29 30 26 26 26 100 64 64 69 88 88 86 78 77 80 81 100 51 51 57 98 92 79 79 77 81 80 100 44 44 50 13 24 1 4 9 10 7 100 64 92 22 22 19 41 41 42 39 39 100 93 93 86 56 59 44 44 45 47 47 100 37 2 97 81 76 76 74 68 67 70 100 76 76 76 76 74 80 79 86 85 100 32 ...
output:
? 1 100 ? 43 100 ? 1 42 ? 19 42 ? 1 18 ? 1 10 ? 1 6 ? 7 10 ? 9 10 ! 10 ? 1 100 ? 1 58 ? 1 34 ? 15 34 ? 23 34 ? 28 34 ? 23 27 ? 25 27 ? 25 26 ! 25 ? 1 100 ? 43 100 ? 43 76 ? 77 100 ? 77 90 ? 83 90 ? 77 82 ? 77 79 ? 80 82 ? 80 81 ! 82 ? 1 100 ? 43 100 ? 43 76 ? 77 100 ? 87 100 ? 77 86 ? 77 82 ? 77 79 ...
result:
ok Correct (10000 test cases)
Test #8:
score: -100
Wrong Answer
time: 0ms
memory: 3776kb
input:
1000 1000 475 426 728 747 896 896 926 867 867 858 844 844 845 847 847 1000 278 17 974 811 598 598 637 679 665 652 655 640 640 641 643 1000 75 128 871 985 607 644 686 713 749 749 755 742 742 741 739 1000 239 239 45 577 577 520 442 442 458 460 460 460 462 463 1000 978 978 978 978 978 997 914 914 920 9...
output:
? 1 1000 ? 1 580 ? 581 1000 ? 581 824 ? 825 1000 ? 825 926 ? 868 926 ? 825 867 ? 843 867 ? 854 867 ? 843 853 ? 843 848 ? 843 845 ? 846 848 ? 846 847 ! 846 ? 1 1000 ? 1 580 ? 581 1000 ? 757 1000 ? 581 756 ? 581 682 ? 581 639 ? 640 682 ? 658 682 ? 640 657 ? 648 657 ? 640 647 ? 640 644 ? 640 642 ? 643 ...
result:
wrong answer Too many queries , n = 1000 , now_q 16 (test case 109)