QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#319015 | #6303. Inversion | KiharaTouma | WA | 4ms | 3888kb | C++23 | 1.1kb | 2024-02-01 15:22:41 | 2024-02-01 15:22:42 |
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], nw;
int ask(int l, int r){
if(l >= r){
return 0;
}
if(r < nw){
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] = vl;
if(a[j] > a[i]){
-- vl;
}
}
}
printf("! ");
for(int i = 1; i <= n; ++ i){
printf("%d ", a[i]);
}
fflush(stdout);
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3788kb
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: 4ms
memory: 3888kb
input:
1993 0 0 0 1 1 0 0 1 0 0 0 0 0 0 0 1 0 0 1 1 1 0 1 1 0 1 1 1 0 0 0 1 1 0 0 0 1 1 0 1 1 0 1 0 1 0 0 1 1 1 1 1 1 0 1 0 1 1 0 0 0 0 1 1 0 0 0 1 0 0 1 1 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 1 1 0 1 0 1 0 0 0 0 1 0 0 0 0 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 0 1 0 1 1 1 0 0 1 0 0 1 0 1 0 0 0 0 1 1 1 1 0 1 0 1 1 1 1 1 1...
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 ? 7 8 ? 8 9 ? 2 9 ? 3 9 ? 4 9 ? 5 9 ? 3 9 ? 4 9 ? 8 10 ? 9 10 ? 9 10 ? 1 10 ? 2 10 ? 2 10 ? 3 10 ? 8 11 ? 9 11 ? 11 12 ? 12 13 ? 13 14 ? 3 14 ? 4 14 ? 10 14 ? 11 14 ? 9 14 ? 10 14 ? 2 14 ? 3 14 ? 13...
result:
wrong answer Wa.