QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#319018#6303. InversionKiharaToumaWA 49ms3992kbC++231.1kb2024-02-01 15:30:092024-02-01 15:30:09

Judging History

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

  • [2024-02-01 15:30:09]
  • 评测
  • 测评结果:WA
  • 用时:49ms
  • 内存:3992kb
  • [2024-02-01 15:30:09]
  • 提交

answer

//qoj6303
#include <bits/stdc++.h>
using namespace std; typedef long long ll;
void solve();int main(){ solve(); return 0; }

const int N = 2010;
int n, nx[N], ps[N], a[N], nw;

int ask(int l, int r){
	if(l >= r){
		return 0;
	}
	if(r <= nw - 1){
		return nx[l];
	}
	printf("? %d %d\n", l, r);
	fflush(stdout);
	int x;
	scanf("%d", &x);
	return x;
}
bool chk(int l, int r){
	return ask(l, r) - ask(l+1, r) - ask(l, r-1) + ask(l+1, r-1);
}

void solve(){
	scanf("%d", &n);
	ps[1] = a[1] = 1;
	for(int i = 2; i <= n; ++ i){
		nw = i;
		if(!chk(ps[i-1], i)){
			a[i] = ps[i] = i;
		} else {
			int l = 1, r = i - 1;
			while(l < r){
				int mid = l + r >> 1;
				if(chk(ps[mid], i)){
					r = mid;
				} else {
					l = mid + 1;
				}
			}
			a[i] = l;
			for(int j = 1; j < i; ++ j){
				if(a[j] >= l){
					++ a[j];
				}
				ps[a[j]] = j;
			}
			ps[a[i]] = i;
		}
		int vl = i - a[i];
		for(int j = 1; j < i; ++ j){
			nx[j] = (nx[j] + vl) % 2;
			if(a[j] > a[i]){
				-- vl;
			}
		}
	}
	printf("! ");
	for(int i = 1; i <= n; ++ i){
		printf("%d ", a[i]);
	}
	fflush(stdout);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
0
1
0
1

output:

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

result:

ok OK, guesses=4

Test #2:

score: -100
Wrong Answer
time: 49ms
memory: 3992kb

input:

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

output:

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

result:

wrong output format Unexpected end of file - int32 expected