QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#297500#6303. InversiontangledWA 58ms19256kbC++204.7kb2024-01-04 16:44:262024-01-04 16:44:27

Judging History

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

  • [2024-01-04 16:44:27]
  • 评测
  • 测评结果:WA
  • 用时:58ms
  • 内存:19256kb
  • [2024-01-04 16:44:26]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int N = 2010;
const ll mod = 998244353;
// const ll mod=1e9+7;
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, a, n) for (int i = n; i >= a; i--)
#define vi vector<int>
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define sz(a) ((int)(a).size())
#define me(f, x) memset(f, x, sizeof(f))
#define uint unsigned int
#define ull unsigned long long
#define i128 __int128
#define pb emplace_back
#define pii pair<int, int>
#define debug(x) std::cout << x << endl
// #define endl '\n'
#define mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
ll powmod(ll a, ll b)
{
    ll res = 1;
    a %= mod;
    assert(b >= 0);
    for (; b; b >>= 1)
    {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}
template <typename type>
inline void read(type &x)
{
    x = 0;
    bool flag(0);
    char ch = getchar();
    while (!isdigit(ch))
        flag = ch == '-', ch = getchar();
    while (isdigit(ch))
        x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    flag ? x = -x : 0;
}
template <typename type>
inline void write(type x, bool mode = 1) // 0为空格,1为换行
{
    x < 0 ? x = -x, putchar('-') : 0;
    static short Stack[50], top(0);
    do
        Stack[++top] = x % 10, x /= 10;
    while (x);
    while (top)
        putchar(Stack[top--] | 48);
    mode ? putchar('\n') : putchar(' ');
}
// head~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// begin~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// end~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int a[N], n, dis[N][N];
bool query(int l, int r)
{
    int cnt = 0, x;
    if (l > r)
    {
        swap(l, r);
    }
    if (r - l <= 1)
    {
        if (dis[l][r] == -1)
        {
            cout << "? " << l << " " << r << endl;
            cout.flush();
            cin >> x;
            dis[l][r] = x;
        }
        else
        {
            x = dis[l][r] % 2;
        }
        return x % 2;
    }
    if (dis[l][r] == -1)
    {
        cout << "? " << l << " " << r << endl;
        cout.flush();
        cin >> x;
        dis[l][r] = x;
        cnt += dis[l][r] % 2;
    }
    else
    {
        cnt += dis[l][r] % 2;
    }
    if (dis[l + 1][r] == -1)
    {
        cout << "? " << l + 1 << " " << r << endl;
        cout.flush();
        cin >> x;
        dis[l + 1][r] = x;
        cnt -= dis[l + 1][r] % 2;
    }
    else
    {
        cnt -= dis[l + 1][r] % 2;
    }
    if (dis[l][r - 1] == -1)
    {
        cout << "? " << l << " " << r - 1 << endl;
        cout.flush();
        cin >> x;
        dis[l][r - 1] = x;
        cnt -= dis[l][r - 1] % 2;
    }
    else
    {
        cnt -= dis[l][r - 1] % 2;
    }
    if (dis[l + 1][r - 1] == -1)
    {
        cout << "? " << l + 1 << " " << r - 1 << endl;
        cout.flush();
        cin >> x;
        dis[l + 1][r - 1] = x;
        cnt += dis[l + 1][r - 1] % 2;
    }
    else
    {
        cnt += dis[l + 1][r - 1] % 2;
    }
    return (cnt % 2 + 2) % 2;
}
int ans[N];
void solve()
{
    cin >> n;
    // vector<int> q;
    for (int i = 1; i <= n; i++)
    {
        a[i] = i;
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (i == j)
            {
                dis[i][j] = 0;
            }
            else
            {
                dis[i][j] = -1;
            }
        }
    }
    ans[1] = a[1];
    for (int i = 2; i <= n; i++)
    {
        int l = 1, r = i - 1;
        while (l < r)
        {
            int mid = (l + r) >> 1;
            if (query(ans[mid], a[i]))
            {
                r = mid;
            }
            else
            {
                l = mid + 1;
            }
        }
        if (!query(ans[i - 1], i))
        {
            ans[i] = i;
            continue;
        }
        for (int j = i - 1; j >= l; j--)
        {
            ans[j + 1] = ans[j];
        }
        ans[l] = i;
        int cnt = 0;
        for (int j = i - 1; j >= l; j--)
        {
            if (ans[j] > ans[i])
                cnt++;
            dis[j][i] = dis[j][i - 1] + cnt;
        }
    }
    cout << "! ";
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (ans[j] == i)
            {
                cout << j << " ";
            }
        }
    }
    cout << endl;
}

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int _ = 1;
    while (_--)
    {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 58ms
memory: 19256kb

input:

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

output:

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

result:

wrong output format Unexpected end of file - int32 expected