QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#297615#6303. InversionyokeffCompile Error//C++201.5kb2024-01-04 20:18:522024-01-04 20:18:52

Judging History

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

  • [2024-01-04 20:18:52]
  • 评测
  • [2024-01-04 20:18:52]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
//#define endl '\n'
using namespace std;

const int N=2e3+10;
const int mod=1e8;
typedef pair<int,int>PII;
int f[N][N];
int b[N],c[N],d[N];
int cnt=0;
int qr(int l,int r)
{
	if(l>=r)return 0;
	if(f[l][r]!=-1)return f[l][r];
	cout<<"? "<<l<<" "<<r<<endl;
	cnt++;
//	assert(cnt<=60000);
	cin>>f[l][r];
	return f[l][r];
}
bool check(int l,int r)
{
	return (qr(l,r)^qr(l+1,r)^qr(l,r-1)^qr(l+1,r-1));
}
void solve()
{
	memset(f,-1,sizeof f);
	for(int i=1;i<=n;i++)f[i][i]=0;
	int n;
	cin>>n;
	c[1]=1,b[1]=1;
	for(int i=2;i<=n;i++)
	{
	//	cout<<":: "<<endl;
	//	for(int j=1;j<i;j++)cout<<b[j]<<" ";cout<<endl;
		int l=1,r=i-1;
		while(l<r)
		{
			int mid=l+r>>1;
			if(check(b[mid],i))r=mid;
			else l=mid+1;
		}
	//4	if(l==2&&i==3)cout<<check(l,i)<<endl;
		int pos=0;
		if(check(b[l],i))
		{
	//		cout<<"YE"<<endl;
			for(int j=l;j<i;j++)c[j+1]=b[j];
			c[l]=i,pos=l;
			for(int j=1;j<l;j++)c[j]=b[j];
		}
		else
		{
			for(int j=1;j<=l;j++)c[j]=b[j];
			c[i]=i,pos=i;
		}
		for(int j=1;j<=i;j++)d[c[j]]=j;
		for(int j=i-1;j>=1;j--)f[j][i]=f[j+1][i]^(d[j]>d[i]);
		for(int j=1;j<i;j++)f[j][i]^=f[j][i-1];
//		for(int j=1;j<=i;j++)cout<<c[j]<<" ";cout<<endl;
		for(int j=i;j>=1;j--)b[j]=c[j];
	}
	cout<<"! ";
	vector<int>ans(n+1,0);
	for(int i=1;i<=n;i++)ans[c[i]]=i;
	for(int i=1;i<=n;i++)cout<<ans[i]<<" ";
	cout<<endl;
}
signed main()
{
//	ios::sync_with_stdio(false);
//	cin.tie(0);
//	cout.tie(0);
	int t=1;
//	cin>>t;
	while(t--)solve();
	return 0;
}

Details

answer.code: In function ‘void solve()’:
answer.code:29:24: error: ‘n’ was not declared in this scope
   29 |         for(int i=1;i<=n;i++)f[i][i]=0;
      |                        ^