QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#441796#6303. Inversionjames1BadCreeper#WA 86ms19352kbC++171.2kb2024-06-14 18:19:232024-06-14 18:19:24

Judging History

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

  • [2024-06-14 18:19:24]
  • 评测
  • 测评结果:WA
  • 用时:86ms
  • 内存:19352kb
  • [2024-06-14 18:19:23]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 2005;

int n, a[N], ord[N], ans[N][N];
int ask(int l, int r) {
    if (l >= r) return 0; 
    if (ans[l][r] != -1) return ans[l][r]; 
    cout << "? " << l << ' ' << r << endl; 
    return cin >> ans[l][r], ans[l][r];
}
int cmp(int l, int r) {
    int num = ask(l, r) ^ ask(l, r - 1) ^ ask(l + 1, r) ^ ask(l + 1, r - 1);
    return num == 1; 
}
int main(void) {
    ios::sync_with_stdio(0); 
    cin >> n; 
    memset(ans, -1, sizeof ans); 
    ord[1] = a[1] = 1; 
    for (int i = 2; i <= n; ++i) {
        int l = 0, r = i; 
        while (l + 1 != r) {
            int mid = l + r >> 1; 
            if (cmp(ord[mid], i)) r = mid; // a[ord[mid]] > a[i]
            else l = mid; 
        }
        // a[ord[l]] < a[i]
        for (int j = i - 1; j >= r; --j) ord[j + 1] = ord[j]; 
        ord[r] = i; 

        for (int j = 1; j <= i; ++j) a[ord[j]] = j; 
        // for (int j = i - 1; j >= 1; --j) ans[j][i] = (ans[j + 1][i] ^ (a[j] > a[i])); 
        // for (int j = 1; j < i; ++j) ans[j][i] ^= ans[j][i - 1]; 
    }
    cout << "! ";
    for (int i = 1; i <= n; ++i) cout << a[i] << ' '; 
    cout << endl; 
    return 0; 
}

詳細信息

Test #1:

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

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: 86ms
memory: 19352kb

input:

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

output:

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

result:

wrong output format Unexpected end of file - int32 expected