QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#627564#6303. InversionMCdycWA 100ms7476kbC++232.0kb2024-10-10 16:20:022024-10-10 16:20:02

Judging History

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

  • [2024-10-10 16:20:02]
  • 评测
  • 测评结果:WA
  • 用时:100ms
  • 内存:7476kb
  • [2024-10-10 16:20:02]
  • 提交

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;
    auto cal = [&](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);
    for (int i = 0; i < n; i++)
    {
        if (a.empty())
        {
            a.emplace_back(i);
        }
        else
        {

            int l = 0, r = a.size() - 1;
            int ans = 0;
            while (l <= r)
            {
                int mid = l + r >> 1;
                if (cal(a[mid], i))
                {
                    l = mid + 1;
                }
                else
                {
                    ans = mid;
                    r = mid - 1;
                }
            }
            a.insert(a.begin() + l, i);
        }
    }
    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;
}

详细

Test #1:

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

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: 100ms
memory: 7476kb

input:

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

output:

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

result:

wrong output format Unexpected end of file - int32 expected