QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#303601#6303. InversionxuyufeiyaWA 96ms3764kbC++201.7kb2024-01-12 19:55:332024-01-12 19:55:33

Judging History

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

  • [2024-01-12 19:55:33]
  • 评测
  • 测评结果:WA
  • 用时:96ms
  • 内存:3764kb
  • [2024-01-12 19:55:33]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin >> n;

    auto query = [](auto self, int x, int y) -> int {
        if(x > y)   return -self(self, y, x);
        if(x == 0)  return -1;
        int ret = 0, a;
        if(x + 1 == y) {
            printf("? %d %d\n", x, y);
            fflush(stdout);
            cin >> a;
            ret ^= a;
        } else {
            printf("? %d %d\n", x + 1, y);
            fflush(stdout);
            cin >> a;
            ret ^= a;
            printf("? %d %d\n", x, y - 1);
            fflush(stdout);
            cin >> a;
            ret ^= a;
            printf("? %d %d\n", x, y);
            fflush(stdout);
            cin >> a;
            ret ^= a;

            if(x + 1 != y - 1) {
                printf("? %d %d\n", x + 1, y - 1);
                fflush(stdout);
                cin >> a;
                ret ^= a;
            }
        }
        ret = (ret? 1: -1);
        return ret;
    };
    vector<int> pos;
    pos.push_back(0);

    for(int i = 1; i <= n; i++) {
        int lh = 0, rh = pos.size() - 1, ans = -1;
        while(lh <= rh) {
            int mid = (lh + rh) / 2, tmp;
            if((tmp = query(query, i, pos[mid])) > 0) {
                ans = mid;
                lh = mid + 1;
            } else {
                rh = mid - 1;
            }
        }

        pos.insert(pos.begin() + ans + 1, i);
    }

    vector<int> out(n + 1);
    for(int i = 1; i <= n; i++) out[pos[i]] = i;
    printf("! ");
    for(int i = 1; i <= n; i++) printf("%d%c", out[i], i == n? '\n': ' ');
    fflush(stdout);

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
0
1
0
0

output:

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

result:

ok OK, guesses=4

Test #2:

score: -100
Wrong Answer
time: 96ms
memory: 3764kb

input:

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

output:

? 1 2
? 2 3
? 1 2
? 1 3
? 2 3
? 2 4
? 1 3
? 1 4
? 2 3
? 3 4
? 2 3
? 2 4
? 3 4
? 3 5
? 2 4
? 2 5
? 3 4
? 2 5
? 1 4
? 1 5
? 2 4
? 2 6
? 1 5
? 1 6
? 2 5
? 5 6
? 2 7
? 1 6
? 1 7
? 2 6
? 6 7
? 5 6
? 5 7
? 7 8
? 6 7
? 6 8
? 3 8
? 2 7
? 2 8
? 3 7
? 4 8
? 3 7
? 3 8
? 4 7
? 2 9
? 1 8
? 1 9
? 2 8
? 8 9
? 3 9
...

result:

wrong output format Unexpected end of file - int32 expected