QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#605379#8939. PermutationericmegalovaniaRE 0ms0kbC++201.6kb2024-10-02 16:55:412024-10-02 16:55:43

Judging History

This is the latest submission verdict.

  • [2024-10-02 16:55:43]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 0kb
  • [2024-10-02 16:55:41]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;

//#define ONLINE
#ifndef ONLINE
char DEBUG_BUFFER[1000];
#define debug(...) {sprintf(DEBUG_BUFFER,##__VA_ARGS__);\
cerr<<"\033[1;36m"<<DEBUG_BUFFER<<"\033[0;2m"<<"\033[0m";}
#else
#define debug(...) ;
#endif

using LL=long long;
using PII=pair<int,int>;

#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()

#define FAST_IO {ios::sync_with_stdio(false);cin.tie(nullptr);}
inline int read(){static int x; cin>>x; return x;}
inline LL readLL(){static LL x; cin>>x; return x;}
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

using LD=long double;
LD p=(LD)((LD)sqrt(5)-1)/2;
int cnt,len,mx_cnt,mx_len;
int ask(int l,int r){
	assert(l<r);
	assert(++cnt<=mx_cnt);
	assert((len+=r-l+1)<=mx_len);
	cout<<"? "<<l<<" "<<r<<endl;
	return read();
}
int calc(int l,int r,int pos){
	if(l==r) return l;
	if(l+1==r){
		return pos==l?r:l;
	}
	if(l+2==r){
		if(pos==l) return calc(l+1,r,ask(l+1,r));
		if(pos==r) return calc(l,r-1,ask(l,r-1));
		if(ask(l,pos)==pos) return l;
		else return r;
	}
	int len=r-l+1;
	int mid=p*len+l;
	if(ask(l,mid)==pos) return calc(l,mid,pos);
	return calc(mid+1,r,ask(mid+1,r));
}
void solve(){
	int n=read();
	mx_cnt=ceil((LD)1.5*log2(n)),mx_len=n*3;
	cnt=len=0;
	int ans=calc(1,n,ask(1,n));
	cout<<"! "<<ans<<endl;
}

int main(){
	int T=1;
	cin>>T; //remember this !!!!!!
	while(T--) solve();
	return 0;
}

/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

3
5
3
3
2

output:

? 1 5
? 1 4
? 1 3

result: