QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#297607#6303. InversionyokeffWA 65ms35164kbC++201.4kb2024-01-04 20:06:452024-01-04 20:06:46

Judging History

This is the latest submission verdict.

  • [2024-01-04 20:06:46]
  • Judged
  • Verdict: WA
  • Time: 65ms
  • Memory: 35164kb
  • [2024-01-04 20:06:45]
  • Submitted

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];
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);
	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=i;j>=1;j--)
		{
			if(j>pos)f[c[j]][i]=1;
			else f[c[j]][i]=0;
		}
//		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

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 35008kb

input:

3
0
0
1

output:

? 1 2
? 1 3
? 2 3
! 2 3 1 

result:

ok OK, guesses=3

Test #2:

score: -100
Wrong Answer
time: 65ms
memory: 35164kb

input:

1993
0
0
0
0
0
1
0
0
0
0
0
0
1
0
0
0
1
1
0
0
1
0
0
1
1
1
0
0
1
1
1
1
1
1
0
1
1
0
0
0
0
0
0
0
0
0
0
0
1
0
0
1
1
1
1
1
1
0
1
1
1
1
1
1
0
0
1
0
0
0
0
0
0
1
1
1
0
1
0
1
1
1
1
0
1
1
1
0
1
1
0
1
1
0
1
0
0
0
1
0
0
0
1
0
0
0
1
1
1
1
1
1
1
0
1
0
1
1
0
1
1
0
0
1
1
0
1
1
0
1
0
0
1
1
0
1
1
0
1
0
1
0
1
0
1
0
1
1...

output:

? 1 2
? 1 3
? 2 3
? 2 4
? 3 4
? 2 5
? 3 5
? 1 5
? 2 6
? 3 6
? 4 6
? 5 6
? 2 7
? 3 7
? 1 7
? 5 7
? 6 7
? 2 8
? 3 8
? 5 8
? 6 8
? 7 8
? 1 9
? 2 9
? 8 9
? 7 9
? 1 10
? 2 10
? 3 10
? 4 10
? 6 10
? 7 10
? 1 11
? 2 11
? 10 11
? 6 11
? 7 11
? 2 12
? 3 12
? 11 12
? 6 12
? 7 12
? 2 13
? 3 13
? 11 13
? 12 13
...

result:

wrong answer Wa.