QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#607319#8939. PermutationKanate#TL 1ms3692kbC++142.0kb2024-10-03 14:40:482024-10-03 14:40:52

Judging History

This is the latest submission verdict.

  • [2024-10-03 14:40:52]
  • Judged
  • Verdict: TL
  • Time: 1ms
  • Memory: 3692kb
  • [2024-10-03 14:40:48]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define rint int
// #define endl '\n'
#define uint unsigned long long
void debug(int *a,int n){for(rint i=1;i<=n;i++) cout<<a[i]<<" ";cout<<endl;}
void debug(int *a){for(rint i=1;a[i];i++) cout<<a[i]<<" ";cout<<endl;}
void debug(int x){cout<<"debug: "<<x<<endl;}
int read(){
    int x=0,f=1;char c=getchar();
    while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
    while(isdigit(c))x=x*10+c-48,c=getchar();
    return x*f;
}const int N=1e6+10,p=1e9,mod=998244353;

int ask(int l,int r)
{
	cout<<"? "<<l<<" "<<r<<endl;
	return read();
}

void work0(int l,int r);
void work1(int l,int r);
void work2(int l,int r);

bool use[N];
void work0(int l,int r)
{
	if(l==r) return cout<<"! "<<l<<endl,void();
	int x=ask(l,r);use[x]=1;
	int llen=x-l+1,rlen=r-x+1;
	if(llen<rlen)
	{
		if(llen==1) return work1(x+1,r);
		int y=ask(l,x);
		
		if(y==x) return work1(l,x-1);
		else return work1(x+1,r);
	}
	else
	{
		if(rlen==1) return work1(l,x-1);
		int y=ask(x,r);
		if(y==x) return work1(x+1,r);
		else return work1(l,x-1);
	}
}
void work1(int l,int r)
{
	if(l==r) return cout<<"! "<<l<<endl,void();
	if(use[l-1])
	{
		int x=l-1+(r-l+1)*2/3,y=ask(l-1,x);
		if(y==l-1) return work1(l,x);
		else return work0(x+1,r);
	}
	else
	{
		int x=r+1-(r-l+1)*2/3,y=ask(x,r+1);
		if(y==r+1) return work1(x,r);
		else return work0(l,x-1);
	}
}

bool check(int l,int r,int mid)
{
	if(ask(l-1,mid)==l-1) return 1;
	return 0;
}
void work2(int l,int r)
{
	int ll=l,rr=r+1;
	while(ll+1<rr)
	{
		int mid=(ll+rr)>>1;
		if(check(l,r,mid)) rr=mid+1;
		else ll=mid+1;
	}
	cout<<"! "<<l<<endl,void();
}

void Work()
{
	int n=read();
	for(rint i=0;i<=n+1;i++) use[i]=0;
	work0(1,n);
}

signed main()
{
    #ifndef ONLINE_JUDGE
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);
	#else
	#endif
    
	// int T=1;
	int T=read();
	while(T--) Work();
	
    return 0;
}

詳細信息

Test #1:

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

input:

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

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: -100
Time Limit Exceeded

input:

10000
10
2
1
2
2
2

output:

? 1 10
? 1 2
? 2 7
? 2 5
? 2 4
? 2 3

result: