QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#694641#6303. Inversionucup-team2179#WA 58ms73148kbC++201.6kb2024-10-31 18:23:162024-10-31 18:23:16

Judging History

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

  • [2024-10-31 18:23:16]
  • 评测
  • 测评结果:WA
  • 用时:58ms
  • 内存:73148kb
  • [2024-10-31 18:23:16]
  • 提交

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, sum[N], ans[N][N], vis[N][N];
int ask(int l, int r){
    if(l == r)
        return 0;
    if(vis[l][r])
        return ans[l][r];
    cout << "? " << l << " " << r << '\n';
    cout.flush();
    cnt++;
    assert(cnt <= 40000);
    int x;
    cin >> x;
    ans[l][r] = x;
    vis[l][r] = 1;
    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) ^ sum[pos[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) ^ sum[pos[mid]])
                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;
            }
        sum[i] = 0;
        for(int j = i; j >= 1; j--)
            if(p[j] > p[i])
                sum[j] = sum[j + 1] ^ 1;
            else
                sum[j] = sum[j + 1];
    }
    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: 5720kb

input:

3
0
1
0

output:

? 1 2
? 2 3
? 1 3
! 2 3 1

result:

ok OK, guesses=3

Test #2:

score: -100
Wrong Answer
time: 58ms
memory: 73148kb

input:

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

output:

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

result:

wrong answer Wa.