QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#694529#6303. Inversionucup-team2179#WA 113ms3716kbC++201.3kb2024-10-31 18:07:562024-10-31 18:08:02

Judging History

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

  • [2024-10-31 18:08:02]
  • 评测
  • 测评结果:WA
  • 用时:113ms
  • 内存:3716kb
  • [2024-10-31 18:07:56]
  • 提交

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];
int ask(int l, int r){
    if(l == r)
        return 0;
    cout << "? " << l << " " << r << '\n';
    cout.flush();
    int x;
    cin >> x;
    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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3716kb

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: 113ms
memory: 3620kb

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:

wrong output format Unexpected end of file - int32 expected