QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#607515#8939. PermutationKanateRE 1ms3780kbC++141.4kb2024-10-03 15:08:082024-10-03 15:08:11

Judging History

This is the latest submission verdict.

  • [2024-10-03 15:08:11]
  • Judged
  • Verdict: RE
  • Time: 1ms
  • Memory: 3780kb
  • [2024-10-03 15:08:08]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
double A = (sqrt(5)-1)/2.0;
int solve1(int l,int r);
int solve2(int l,int r);
int solve0(int l,int r);
int sum ,n ,cnt , K;int T;
int ask(int x,int y){
	cnt ++ ;
	sum += y-x+1;
	assert(cnt <= K);
	int ans;
	cout << "? " << x << " " << y << endl;cout.flush();
	cin >> ans;
	return ans;
}
// 
int solve0(int l,int r){
	if(l==r){
		return l;
	}
	int x = ask(l,r);
	if(x==l) return solve1(l,r);
	if(x==r) return solve2(l,r);
	int len1 = x - l + 1;
	int len2 = r - x + 1;
	if(len1<=len2 || rand()%3==0){
		int y = ask(l,x);
		if(y==x) return solve2(l,x);
		else return solve1(x,r);
	}else {
		int y = ask(x,r);
		if(y==x) return solve1(x,r);
		return solve2(l,x);
	}
}
// 左端
int solve1(int l,int r){
	if(l==r) return l;
	if(r-l==1) return l + 1;
	int len = max(A * (double)(r-l+1),2.0);
	int x = ask(l,l+len-1);
	if(x == l) return solve1(l,l+len-1);
	else return solve0(l+len,r);
}
int solve2(int l,int r){
	if(l==r) return l;
	if(r-l==1) return l;
	int len = max(A * (double)(r-l+1),2.0);
	int x = ask(r-len+1,r);
	if(x == r) return solve2(r-len+1,r);
	else return solve0(l,r-len);
}

signed main()
{
	srand(time(0));
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> T;
	while(T-->0){
		cin >> n;
		sum = 0;
		cnt = 0 ;
		K = ceil(1.5 *log2(n));
		int ans =  solve0(1,n) ;
		cout << "!" << " " << ans << endl;
		cout.flush();
	}
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
5
3
2
3
6
6
5
3
3
4
3
3

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: -100
Runtime Error

input:

10000
10
2
1
2
2
3
10
10
10
8
5
5
10
5
1
5
6
10
4
4
4
10
10
6
3
4
2
10
3
3
2
10
1
5
9
9
9
10
1
3
8
8
10
2
1
4
9
9
10
3
1
3
3
10
4
1
7
8
9
10
8
8
7
1
2

output:

? 1 10
? 1 2
? 2 6
? 2 4
? 2 3
! 4
? 1 10
? 5 10
? 8 10
? 5 7
? 5 6
! 6
? 1 10
? 1 5
? 5 7
? 5 6
! 7
? 1 10
? 1 4
? 3 4
! 3
? 1 10
? 5 10
? 1 4
? 3 4
? 2 3
! 1
? 1 10
? 1 3
? 2 3
! 1
? 1 10
? 1 6
? 7 10
? 7 9
? 8 9
! 8
? 1 10
? 1 6
? 7 10
? 7 8
! 7
? 1 10
? 1 2
? 2 6
? 7 10
? 9 10
! 10
? 1 10
? 1 3
...

result: