QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#829987#8939. Permutation2021cyqTL 0ms0kbC++142.2kb2024-12-24 15:19:172024-12-24 15:19:19

Judging History

This is the latest submission verdict.

  • [2024-12-24 15:19:19]
  • Judged
  • Verdict: TL
  • Time: 0ms
  • Memory: 0kb
  • [2024-12-24 15:19:17]
  • Submitted

answer

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define bll __int128
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define sec second
#define vii vector<int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define pii pair<int,int>
#define pil pair<int,ll>
#define re register
#define puu pair<ull,ull>
#define clr clear
#define vpi vector<pii>
#define qii queue<int>
using namespace std;
namespace io{
	const int __SIZE=(1<<22)+1;
	char ibuf[__SIZE],*iS,*iT,obuf[__SIZE],*oS=obuf,*oT=oS+__SIZE-1,__c,qu[55];int __f,qr,_eof;
#define Gc()(iS==iT?(iT=(iS=ibuf)+fread(ibuf,1,__SIZE,stdin),(iS==iT?EOF:*iS++)):*iS++)
	inline void flush(){fwrite(obuf,1,oS-obuf,stdout),oS=obuf;}
	inline void gc(char&x){x=Gc();}
	inline void pc(char x){*oS++=x;if(oS==oT)flush();}
	inline void pstr(const char*s){int __len=strlen(s);for(__f=0;__f<__len;++__f)pc(s[__f]);}
	inline void gstr(char*s){for(__c=Gc();__c<32||__c>126||__c==' ';)__c=Gc();
		for(;__c>31&&__c<127&&__c!=' ';++s,__c=Gc())*s=__c;*s=0;}
	template<class I>inline bool read(I&x){_eof=0;
		for(__f=1,__c=Gc();(__c<'0'||__c>'9')&&!_eof;__c=Gc()){if(__c=='-')__f=-1;_eof|=__c==EOF;}
		for(x=0;__c<='9'&&__c>='0'&&!_eof;__c=Gc())x=x*10+(__c&15),_eof|=__c==EOF;x*=__f;return!_eof;}
	template<class I>inline void write(I x){if(!x)pc('0');if(x<0)pc('-'),x=-x;
		while(x)qu[++qr]=x%10+'0',x/=10;while(qr)pc(qu[qr--]);}
	struct Flusher_{~Flusher_(){flush();}}io_flusher_;
}using io::pc;using io::gc;using io::pstr;using io::gstr;using io::read;using io::write;
const double G=(sqrt(5)-1.0)/2.0;
int ask(int l,int r)
{
	if(l==r)return 0;
	int x;
	cout<<"? "<<l<<" "<<r<<endl;
	cin>>x;
	return x;
}
void find(int l,int r,int x)
{
	if(l==r){printf("! %d",l),cout<<endl;return ;}
	int mid1=l+G*(r-l+1),mid2=ceil(r-G*(r-l+1)+1);
	if(x<=mid1)
	{
		if(ask(l,mid1)==x)find(l,mid1,x);
		else find(mid1+1,r,ask(mid1+1,r));
	}
	else{
//		if(x<mid2)printf("fuck %d %d %d %d\n",l,r,mid1,mid2);
		if(ask(mid2,r)==x)find(mid2,r,x);
		else find(l,mid2-1,ask(l,mid2-1));
	}
}
int main()
{
	int T,n;scanf("%d",&T);
	while(T--)scanf("%d",&n),find(1,n,ask(1,n));
}

詳細信息

Test #1:

score: 0
Time Limit Exceeded

input:

3
5
3
3
2
6
6
5
3
1

output:

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

result: