QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#694844#6303. Inversionucup-team2179#RE 0ms3592kbC++201.7kb2024-10-31 18:47:202024-10-31 18:47:24

Judging History

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

  • [2024-10-31 18:47:24]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3592kb
  • [2024-10-31 18:47:20]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define ll long long
#define pii pair<int, int>
using namespace std;
const int N = 2999;
int n, pos[N], p[N], cnt;
int ask(int l, int r){
    if(l == r)
        return 0;
    cout << "? " << l << " " << r << '\n';
    cout.flush();
    cnt++;
    assert(cnt <= 40000);
    int x;
    cin >> x;
    return x;
}
//int a[N] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
// int ask(int l, int r){
//     //cout << l << " " << r << '\n';
//     int x = 0;
//     for (int i = l; i <= r; i++)
//         for (int j = i + 1; j <= r; j++)
//             if(a[j] < a[i])
//                 x ^= 1;
//     //cout << x << '\n';
//     return x;
// }
int count(int id, int l, int r){
    int x = 0;
    for (int j = l; j <= r; j++)
        if(p[j] < p[id])
            x ^= 1;
    return x;
}
signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    pos[1] = p[1] = 1;
    for (int i = 2; i <= n; i++){
        if(ask(pos[i-1], i) == ask(pos[i-1] + 1, i) ^ count(pos[i-1], pos[i-1], i-1)){
            p[i] = i;
            pos[i] = i;
            continue;
        }
        int l = 1, r = i - 1, mid;
        while(l < r){
            mid = (l + r) >> 1;
            if(ask(pos[mid], i) != ask(pos[mid] + 1, i) ^ count(pos[mid], pos[mid], i-1))
                r = mid;
            else
                l = mid + 1;
        }
        p[i] = l;
        pos[l] = i;
        for (int j = 1; j < i; j++)
            if(p[j] >= l){
                p[j]++;
                pos[p[j]] = j;
            }
    }
    cout << "! ";
    for(int i = 1; i <= n; i++)
        cout << p[i] << " \n"[i == n];
    cout.flush();
    return 0;
}

詳細信息

Test #1:

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

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
Runtime Error

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
1
0
0
0
1
1
1
1
1
1
0
0
1
1
0
1
1
0
1
1
1
1
1
1
0
1
0
0
0
0
0
0
0
1
0
1
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: