QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#319011 | #6303. Inversion | KiharaTouma | WA | 15ms | 3856kb | C++23 | 961b | 2024-02-01 15:19:54 | 2024-02-01 15:19:55 |
Judging History
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];
int ask(int l, int r){
if(l >= r){
return 0;
}
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){
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;
}
}
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: 3856kb
input:
3 0 1 0 1 0
output:
? 1 2 ? 2 3 ? 1 3 ? 2 3 ? 1 2 ! 2 3 1
result:
ok OK, guesses=5
Test #2:
score: -100
Wrong Answer
time: 15ms
memory: 3796kb
input:
1993 0 0 0 1 1 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 1 0 1 0 0 0 0 1 0 0 1 0 1 0 0 0 1 0 0 1 0 1 0 0 0 1 1 0 1 0 0 1 0 0 0 1 0 1 1 1 1 1 0 1 1 0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 0 0 1 0 1 1 1 1 0 1 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 1 0 0 0 0 1 0 1 0 0 0 1 0 0 1 1 0 0 1 0 0 0 0 0 1 1 0 1 0 1 1 1 0 1 1...
output:
? 1 2 ? 2 3 ? 3 4 ? 4 5 ? 2 5 ? 3 5 ? 2 4 ? 3 4 ? 1 5 ? 2 5 ? 1 4 ? 2 4 ? 4 6 ? 5 6 ? 4 5 ? 2 6 ? 3 6 ? 2 5 ? 3 5 ? 1 6 ? 2 6 ? 1 5 ? 2 5 ? 5 6 ? 4 7 ? 5 7 ? 4 6 ? 5 6 ? 1 7 ? 2 7 ? 1 6 ? 2 6 ? 6 7 ? 5 7 ? 6 7 ? 5 6 ? 4 8 ? 5 8 ? 4 7 ? 5 7 ? 1 8 ? 2 8 ? 1 7 ? 2 7 ? 3 8 ? 4 8 ? 3 7 ? 4 7 ? 2 8 ? 3 8 ...
result:
wrong output format Unexpected end of file - int32 expected