QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#858251#8939. PermutationiniTL 76ms3584kbC++14632b2025-01-16 15:20:322025-01-16 15:21:08

Judging History

This is the latest submission verdict.

  • [2025-01-16 15:21:08]
  • Judged
  • Verdict: TL
  • Time: 76ms
  • Memory: 3584kb
  • [2025-01-16 15:20:32]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
int n,res;
int query(int l,int r){
	cout<<"? "<<l<<" "<<r<<"\n";
	cout<<flush;
	int p;cin>>p;
	return p;
}
void merge(int l,int r,int sec){
	if(r-l==1){
		if(sec==r)res=l;
		else res=r;
		return;
	}
	int mid=l+(double)(r-l)*0.618;
	if(sec<=mid){
		if(query(l,mid)==sec)merge(l,mid,sec);
		else merge(mid+1,r,query(mid+1,r));
	}
	else{
		mid=l+(double)(r-l)*0.382;
		if(query(mid+1,r)==sec)merge(mid+1,r,sec);
		else merge(l,mid,query(l,mid));
	}
}
int main(){
	int T;cin>>T;
	while(T--){
		cin>>n;
		merge(1,n,query(1,n));
		cout<<"! "<<res<<endl;
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 76ms
memory: 3584kb

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
Time Limit Exceeded

input:

10000
3
1
2

output:

? 1 3
? 1 2
? 3 3

result: