QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#470376#6394. Turn on the LightUESTC_DebugSimulator#WA 1ms3752kbC++17882b2024-07-10 12:25:422024-07-10 12:25:42

Judging History

你现在查看的是最新测评结果

  • [2024-07-10 12:25:42]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3752kb
  • [2024-07-10 12:25:42]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lowbit(i) (i&-i)
#define rand() (myrand())
using namespace std;
mt19937 myrand(time(0));
int n, x;
void ask(int k) {
	cout << "? " << k << endl;
	cin >> x;
}
void solve() {
	cin >> n;
	ask(1);
	if (!x) {
		cout << "! 1" << endl;
		return;
	}
	int l = 2, r = n, last = x;
	while(l < r) {
		int mid = (l + r)>>1;
		ask(mid);
		if (last == x) {
			cout << "! " << mid << endl;
			return;
		}
		if (last) {
			if (x > last) l = mid + 1;
			else r = mid;
		} 
		else {
			last = x;
			ask(l);
			l++;
			if (last == x) {
				cout << "! " << mid << endl;
				return;
			}
			if (x < last) r = mid;
			else l = mid + 1;
		}
		last = x;
	}
	cout << "! " << l << endl;
}
signed main(void) {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3712kb

input:

3
1
2

output:

? 1
? 2
! 3

result:

ok Correct position at 3

Test #2:

score: 0
Accepted
time: 1ms
memory: 3624kb

input:

10
1
0
1
0
0

output:

? 1
? 6
? 4
? 2
? 3
! 3

result:

ok Correct position at 3

Test #3:

score: 0
Accepted
time: 0ms
memory: 3680kb

input:

9
1
2
3
3

output:

? 1
? 5
? 7
? 8
! 8

result:

ok Correct position at 8

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3752kb

input:

8
1
0
1
1

output:

? 1
? 5
? 3
? 2
! 3

result:

wrong answer Wrong favorite light!