QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#607494#8939. PermutationUESTC_xxxWA 1ms3864kbC++201.3kb2024-10-03 15:03:382024-10-03 15:03:39

Judging History

This is the latest submission verdict.

  • [2024-10-03 15:03:39]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3864kb
  • [2024-10-03 15:03:38]
  • Submitted

answer

#include<iostream>
#include<cstdio>
#include<cmath>
#define lowbit(x) x&(-x)
#include<queue>
#include<vector>
#include<algorithm>
#define ll long long
using namespace std;
int tt,n,pos,cnt1,cnt2;
double k=0.35;
void solve(int l,int r,int ls){
	if(l==r){
		printf("! %d\n",l);
		fflush(stdout);
		return;
	}
	if(r-l==1){
		printf("? %d %d\n",l,r);
		fflush(stdout);
		scanf("%d",&pos);
		printf("! %d\n",(pos==l)?r:l);
		fflush(stdout);
		cnt1++,cnt2+=r-l+1;
		return;
	}
	if(!ls){
		printf("? %d %d\n",l,r);
		fflush(stdout);
		scanf("%d",&pos);
		cnt1++,cnt2+=r-l+1;
		ls=pos;
	}
	double f1=(r-l+1)*k+l,f2=(r-l+1)*(1-k)+l;
	int m1=f1,m2=f2;
	if(m1+1-f1<f1-m1) m1++;
	if(m2+1-f2<f2-m2) m2++;
	if(ls<=m1){
		printf("? %d %d\n",l,m1);
		fflush(stdout);
		scanf("%d",&pos);
		cnt1++,cnt2+=m1-l+1;
		if(m1-l==1){
			printf("! %d\n",(pos==m1)?l:m1);
			fflush(stdout);
			return;
		}
		if(pos==ls){
			solve(l,m1,ls);
		}
		else solve(m1+1,r,0);
	}
	else{
		printf("? %d %d\n",m2,r);
		fflush(stdout);
		scanf("%d",&pos);
		cnt1++,cnt2+=r-m2+1;
		if(r-m2==1){
			printf("! %d\n",(pos==m2)?r:m2);
			fflush(stdout);
			return;
		}
		if(pos==ls){
			solve(m2,r,ls);
		}
		else solve(l,m2-1,0);
	}
}
int main(){
	scanf("%d",&tt);
	while(tt--){
		cnt1=cnt2=0;
		scanf("%d",&n);
		solve(1,n,0);
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3864kb

input:

3
5
3
2
5
6
6
5

output:

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

result:

wrong answer Wrong prediction (test case 2)