QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#470420 | #6394. Turn on the Light | UESTC_Snow_Halation# | TL | 1ms | 3720kb | C++14 | 848b | 2024-07-10 13:12:09 | 2024-07-10 13:12:09 |
Judging History
answer
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef double db;
const int N = 1e5 + 7;
int query(int pos)
{
static int x;
cout << "? " << pos << endl;
cin >> x;
return x;
}
int main()
{
// ios::sync_with_stdio(false);
int n;
cin >> n;
for (int i = 1; i <= 20; i++)
if (query(i) != i)
{
cout << "! " << i << endl;
return 0;
}
int l = 21, r = n;
int last = 20;
while (l <= r)
{
int mid = (l + r) >> 1;
int x = query(mid);
if (x == last + 1)
l = mid + 1;
else if (x == last)
{
cout << "! " << mid << endl;
return 0;
}
else if (x == last - 1)
r = mid - 1;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3720kb
input:
3 1 2 2
output:
? 1 ? 2 ? 3 ! 3
result:
ok Correct position at 3
Test #2:
score: 0
Accepted
time: 1ms
memory: 3636kb
input:
10 1 2 3 4 5 6 7 8 8
output:
? 1 ? 2 ? 3 ? 4 ? 5 ? 6 ? 7 ? 8 ? 9 ! 9
result:
ok Correct position at 9
Test #3:
score: 0
Accepted
time: 1ms
memory: 3576kb
input:
9 1 2 3 4 5 6 7 7
output:
? 1 ? 2 ? 3 ? 4 ? 5 ? 6 ? 7 ? 8 ! 8
result:
ok Correct position at 8
Test #4:
score: 0
Accepted
time: 1ms
memory: 3636kb
input:
8 1 2 3 4 5 6 6
output:
? 1 ? 2 ? 3 ? 4 ? 5 ? 6 ? 7 ! 7
result:
ok Correct position at 7
Test #5:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
7 1 2 3 4 5 5
output:
? 1 ? 2 ? 3 ? 4 ? 5 ? 6 ! 6
result:
ok Correct position at 6
Test #6:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
6 1 2 3 4 5 5
output:
? 1 ? 2 ? 3 ? 4 ? 5 ? 6 ! 6
result:
ok Correct position at 6
Test #7:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
5 1 2 3 3
output:
? 1 ? 2 ? 3 ? 4 ! 4
result:
ok Correct position at 4
Test #8:
score: 0
Accepted
time: 1ms
memory: 3640kb
input:
4 1 2 3 3
output:
? 1 ? 2 ? 3 ? 4 ! 4
result:
ok Correct position at 4
Test #9:
score: 0
Accepted
time: 1ms
memory: 3576kb
input:
3 1 1
output:
? 1 ? 2 ! 2
result:
ok Correct position at 2
Test #10:
score: 0
Accepted
time: 0ms
memory: 3692kb
input:
2 1 1
output:
? 1 ? 2 ! 2
result:
ok Correct position at 2
Test #11:
score: 0
Accepted
time: 1ms
memory: 3572kb
input:
1 0
output:
? 1 ! 1
result:
ok Correct position at 1
Test #12:
score: -100
Time Limit Exceeded
input:
1000000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 2...
output:
? 1 ? 2 ? 3 ? 4 ? 5 ? 6 ? 7 ? 8 ? 9 ? 10 ? 11 ? 12 ? 13 ? 14 ? 15 ? 16 ? 17 ? 18 ? 19 ? 20 ? 500010 ? 750005 ? 750005 ? 750005 ? 750005 ? 750005 ? 750005 ? 750005 ? 750005 ? 750005 ? 750005 ? 750005 ? 750005 ? 750005 ? 750005 ? 750005 ? 750005 ? 750005 ? 750005 ? 750005 ? 750005 ? 750005 ? 750005 ? ...