QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#298049#6303. InversionPlentyOfPenalty#WA 64ms17320kbC++20912b2024-01-05 16:35:482024-01-05 16:35:48

Judging History

This is the latest submission verdict.

  • [2024-01-05 16:35:48]
  • Judged
  • Verdict: WA
  • Time: 64ms
  • Memory: 17320kb
  • [2024-01-05 16:35:48]
  • Submitted

answer

#include<bits/stdc++.h>
#define all(x) begin(x),end(x)
using namespace std;
const int N=2e3+9;
int n,p[N+10],pos[N+10],q[N+10][N+10];
int cnt=0;
int Que(int l,int r){
	if(l>=r)return 0;
	assert((++cnt)<=40000);
	cout<<"? "<<l<<" "<<r<<"\n";
	cout<<flush;
	int ret;
	cin>>ret;
	return ret;
}
bool Check(int x,int y){
	int a=Que(x,y),b=Que(x+1,y);
	return a^b^q[x][y-1]^q[x+1][y-1];
}
int l,r,mid,fl;
int main(){
#ifndef ONLINE_JUDGE
	//freopen(".in","r",stdin);
#endif
	cin.tie(0)->sync_with_stdio(0);
	cin>>n;
	p[1]=1,pos[1]=1,q[1][1]=0;
	for(int i=2;i<=n;++i){
		l=0,r=i-1;
		while(l<r){
			mid=(l+r+1>>1);
			if(Check(pos[mid],i))r=mid-1;
			else l=mid;
		}
		for(int j=i-1;j>l;--j)++p[pos[j]],pos[j+1]=j;
		p[pos[l+1]=i]=l+1;
		fl=0;
		for(int j=i-1;j>=1;--j)fl^=(p[j]>p[i]),q[j][i]=q[j][i-1]^fl;
	}
	cout<<"! ";
	for(int i=1;i<=n;++i)cout<<p[i]<<" ";
	cout<<flush;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3704kb

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: 64ms
memory: 17320kb

input:

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

output:

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

result:

wrong answer Wa.