QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#666464#8939. Permutationlytqwq#WA 3ms3632kbC++14875b2024-10-22 18:37:342024-10-22 18:37:38

Judging History

This is the latest submission verdict.

  • [2024-10-22 18:37:38]
  • Judged
  • Verdict: WA
  • Time: 3ms
  • Memory: 3632kb
  • [2024-10-22 18:37:34]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1000100;
int n,T;
map<pair<int,int> ,int> dk;
int ask(int l,int r){
	if(dk.count(make_pair(l,r))){
		return dk[make_pair(l,r)];
	}
	if(l==r)return -1;
	cout<<"? "<<l<<" "<<r<<endl;
	int x;
	cin>>x;
	dk[make_pair(l,r)]=x;
	return x;
}
void calc(int l,int r){
	if(l==r){
		cout<<"! "<<l<<endl;
		return ;
	}
	else if(l+1==r){
		int v=ask(l,r);
		cout<<"! "<<l+r-v<<endl;
		return ;
	}
	int v=ask(l,r);
	int mid=l+(r-l+1)/3;
	int mid2=r-(r-l+1)/3;
	//l mid mid+1,mid2-1, mid2,r
	if(v>=mid2){
		int kel=ask(mid+1,r);
		if(kel==v){
			calc(mid+1,r);
		}
		else{
			calc(l,mid);
		}
	}
	else{
		int kel=ask(l,mid2-1);
		if(kel==v){
			calc(l,mid2-1);
		}
		else{
			calc(mid2,r);
		}
	}
}
int main(){
	cin>>T;
	while(T--){
		dk.clear();
		cin>>n;
		calc(1,n);
		
	}
}

详细

Test #1:

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

input:

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

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 3568kb

input:

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

output:

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

result:

wrong answer Wrong prediction (test case 4)