QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#607549#8939. PermutationUESTC_NLNSCompile Error//C++14915b2024-10-03 15:17:072024-10-03 15:17:07

Judging History

This is the latest submission verdict.

  • [2024-10-03 15:17:07]
  • Judged
  • [2024-10-03 15:17:07]
  • Submitted

answer

#include<bits/stdc++.h>
#define pii pair<int,int>
using namespace std;
map<pii,int> mp;
const int N=1e6+5;
void answer(int x)
{
	printf("! %d\n",x);
	fflush(stdout);
	return;
}
int query(int l,int r)
{
	if(mp.find({l,r})!=mp.end()) return mp[{l,r}];
	int x;
	printf("? %d %d\n",l,r);
	fflush(stdout);
	scanf("%d",&x);
	mp[{l,r}]=x;
	return x;
}
void solve(int l,int r)
{
	if(l==r)
	{
		answer(l);
		return;
	}
	int mid=(l+r)/2,lmid,x=query(l,r),y;
	if(l+1==r)
	{
		if(x==l) answer(r);
		else answer(l);
		return;
	}
	len=max(2,(int)((r-l)*0.618+l));
	if(x<=mid)
	{
		y=query(l,l+len-1);
		if(x==y) solve(l,l+len-1);
		else solve(l+len,r);
	}
	else
	{
		y=query(r-len+1,r);
		if(x==y) solve(r-len+1,r);
		else solve(l,r-len);
	}
	return;
}
int T,n;
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d",&n);
		solve(1,n);
		mp.clear();
	}
	return 0;
}

详细

answer.code: In function ‘void solve(int, int)’:
answer.code:36:9: error: ‘len’ was not declared in this scope
   36 |         len=max(2,(int)((r-l)*0.618+l));
      |         ^~~
answer.code: In function ‘int query(int, int)’:
answer.code:18:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |         scanf("%d",&x);
      |         ~~~~~^~~~~~~~~
answer.code: In function ‘int main()’:
answer.code:54:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   54 |         scanf("%d",&T);
      |         ~~~~~^~~~~~~~~
answer.code:57:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   57 |                 scanf("%d",&n);
      |                 ~~~~~^~~~~~~~~