QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#302854#6303. InversionZYF_B#TL 0ms0kbC++141.0kb2024-01-11 14:12:532024-01-11 14:12:55

Judging History

你现在查看的是最新测评结果

  • [2024-01-11 14:12:55]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-01-11 14:12:53]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define re register
#define INF 2147483647
using namespace std;

inline int read()
{
	int f=1,x=0;char s=getchar();
	while(s<'0'||s>'9')
	{
		if(s=='-') f=-1;
		s=getchar();
	}
	while(s>='0'&&s<='9')
	{
		x=x*10+s-48;
		s=getchar();
	}
	return f*x;
}

const int N=2005;
int n;
int mp[N][N],v[N],p[N];
int query(int l,int r)
{
	if(l>=r) return 0; 
	if(mp[l][r]!=-1) return mp[l][r];
	cout<<"? "<<l<<" "<<r<<endl;
	cout.flush();
	int x;
	cin>>x;
	return mp[l][r]=x;
}

int ask(int x,int y)
{
	return query(x,y)^query(x+1,y-1)^query(x,y-1)^query(x+1,y);
}

int main()
{
	memset(mp,-1,sizeof(mp));
	cin>>n;
	v[1]=1;
	for(int i=2;i<=n;i++)
	{
		int l=1,r=i-1,pos=-1;
		while(l<=r)
		{
			int mid=(l+r)>>1;
			if(ask(v[mid],i)) pos=mid,r=mid-1;
			else l=mid; 
		}
		for(int j=i-1;j>=pos;j--) v[j+1]=v[j];
		v[pos]=i;
	}
	cout<<"! ";
	for(int i=1;i<=n;i++) p[v[i]]=i;
	for(int i=1;i<=n;i++) cout<<p[i]<<" ";
	cout.flush();
	return 0;
}

详细

Test #1:

score: 0
Time Limit Exceeded

input:

3
0

output:

? 1 2

result: