QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#876576#9734. Identify ChordyuanruiqiWA 1ms3712kbC++261.9kb2025-01-31 00:27:322025-01-31 00:27:33

Judging History

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

  • [2025-01-31 00:27:33]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3712kb
  • [2025-01-31 00:27:32]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
mt19937 rng(chrono::steady_clock().now().time_since_epoch().count());
void out(int x, int y)
{
    cout << "! " << x << ' ' << y << endl;
}
int ask(int x, int y)
{
    cout << "? " << x << ' ' << y << endl;
    int z;
    cin >> z;
    return z;
}
void solve()
{
    int n;
    cin >> n;
    if (n <= 7)
    {
        for (int i=1;i<=n;++i)
            for (int j=i+2;j<=(i==1?n-1:n);++j)
                if (ask(i, j) == 1) return out(i, j);
        return;
    }
    int x = rng() % n + 1, y = (x + n / 2 - 1) % n + 1;
    for (;;)
    {
        int z = ask(x, y);
        if (z == n / 2)
        {
            if (n % 2 == 0) x = x % n + 1, y = y % n + 1;
            else if ((y - x + n) % n == n / 2) y = y % n + 1;
            else x = x % n + 1;
            continue;
        }
        int p = (x + n - 2) % n + 1, q = x % n + 1;
        int a = 0;
        if (ask(p, y) == z - 1)
        {
            int l = 1, r = (x - y + n) % n - 2;
            while (l < r)
            {
                int m = (l + r + 1) >> 1;
                if (ask((x - 1 + n - m) % n + 1, y) == z - m) l = m;
                else r = m - 1;
            }
            a = (x - 1 + n - r) % n + 1;
        }
        else if (ask(q, y) == z - 1)
        {
            int l = 1, r = (y - x + n) % n - 2;
            while (l < r)
            {
                int m = (l + r + 1) >> 1;
                if (ask((x - 1 + m) % n + 1, y) == z - m) l = m;
                else r = m - 1;
            }
            a = (x - 1 + r) % n + 1;
        }
        else a = x;
        z = ask(a, y) - 1;
        if (ask(a, (y - 1 + z) % n + 1) == 1) out(a, (y - 1 + z) % n + 1);
        else out(a, (y - 1 + n - z) % n + 1);
        break;
    }
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3712kb

input:

2
6
2
2
2
1
1
4

output:

? 1 3
? 1 4
? 1 5
? 2 4
! 2 4

result:

wrong answer format  Unexpected end of file - token expected (test case 2)