QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#244990#6303. Inversionhhoppitree#WA 77ms19672kbC++141.7kb2023-11-09 17:43:342023-11-09 17:43:34

Judging History

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

  • [2023-11-09 17:43:34]
  • 评测
  • 测评结果:WA
  • 用时:77ms
  • 内存:19672kb
  • [2023-11-09 17:43:34]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 2005;

int n, p[N], f[N][N], g[N], s[N];

void modify(int x)
{
    for (; x <= n; x += x & -x) {
        ++s[x];
    }
    return;
}

int query(int x)
{
    int res = 0;
    for (; x; x -= x & -x) {
        res += s[x];
    }
    return res;
}

int query(int x, int y)
{
    if (x >= y) {
        return 0;
    }
    if (~f[x][y]) {
        return f[x][y];
    }
    if (p[y]) {
        return g[x];
    }
    printf("? %d %d\n", x, y);
    fflush(stdout);
    int v;
    scanf("%d", &v);
    return f[x][y] = v;
}

signed main()
{
    memset(f, -1, sizeof(f));
    scanf("%d", &n);
    p[1] = 1;
    for (int i = 2; i <= n; ++i) {
        int l = 1, r = i - 1, res = 0;
        while (l <= r) {
            int mid = (l + r) >> 1, wh = 0;
            for (int j = 1; j < i; ++j) {
                if (p[j] == mid) {
                    wh = j;
                    break;
                }
            }
            if (!(query(wh, i) ^ query(wh, i - 1) ^ query(wh + 1, i) ^ query(wh + 1, i - 1))) {
                res = mid;
                l = mid + 1;
            } else {
                r = mid - 1;
            }
        }
        p[i] = res + 1;
        for (int j = 1; j < i; ++j) {
            if (p[j] > res) {
                ++p[j];
            }
        }
        for (int j = 1; j <= n; ++j) {
            s[j] = 0;
        }
        modify(p[i]);
        for (int j = i - 1; j; --j) {
            g[j] = g[j + 1] + query(p[j]);
            modify(p[j]);
        }
    }
    printf("!");
    for (int i = 1; i <= n; ++i) {
        printf(" %d", p[i]);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 77ms
memory: 19672kb

input:

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

output:

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

result:

wrong answer Wa.