QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#627359#6303. InversionMCdycWA 87ms8444kbC++231.5kb2024-10-10 15:38:302024-10-10 15:38:31

Judging History

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

  • [2024-10-10 15:38:31]
  • 评测
  • 测评结果:WA
  • 用时:87ms
  • 内存:8444kb
  • [2024-10-10 15:38:30]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
// #define int long long
map<pair<int, int>, int> mp;
int ask(int l, int r)
{
    if (l == r)
    {
        return 0;
    }
    if (mp.count({l, r}))
    {
        return mp[{l, r}];
    }
    else
    {
        cout << "? " << l + 1 << " " << r + 1 << endl;
        int x;
        cin >> x;
        return mp[{l, r}] = x;
    }
}
int solve()
{
    int n;
    cin >> n;
    vector<int> a(n);
    iota(all(a), 0);
    sort(all(a), [&](int x, int y) {
        if (x < y)
        {
            if (x == y - 1)
            {
                return ask(x, y) == 0;
            }
            else
            {
                return (((ask(x, y) + ask(x + 1, y - 1) - ask(x + 1, y) - ask(x, y - 1))) % 2 == 0);
            }
        }
        else
        {
            swap(x, y);
            if (x == y - 1)
            {
                return ask(x, y) != 0;
            }
            else
            {
                return (((ask(x, y) + ask(x + 1, y - 1) - ask(x + 1, y) - ask(x, y - 1))) % 2) != 0;
            }
        }
    });
    vector<int> b(n);
    int cnt = 1;
    cout << "! ";
    for (int i = 0; i < n; i++)
    {
        b[a[i]] = cnt++;
    }
    for (int i = 0; i < n; i++)
    {
        cout << b[i] << " \n"[i == n - 1];
    }
    return 0;
}
signed main()
{
    int test = 1;
    while (test--)
    {
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 87ms
memory: 8444kb

input:

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

output:

? 2 997
? 3 996
? 3 997
? 2 996
? 2 1993
? 3 1992
? 3 1993
? 2 1992
? 1 2
? 2 3
? 3 1991
? 2 1991
? 2 4
? 3 4
? 3 1990
? 2 1990
? 2 5
? 3 5
? 2 6
? 3 6
? 2 7
? 3 7
? 2 8
? 3 8
? 3 1989
? 2 1989
? 2 9
? 3 9
? 2 10
? 3 10
? 2 11
? 3 11
? 2 12
? 3 12
? 3 1988
? 2 1988
? 2 13
? 3 13
? 3 1987
? 2 1987
? ...

result:

wrong output format Unexpected end of file - int32 expected