QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#613973#8939. PermutationSy03WA 1ms3536kbC++202.4kb2024-10-05 15:13:372024-10-05 15:17:12

Judging History

This is the latest submission verdict.

  • [2024-10-05 15:17:12]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3536kb
  • [2024-10-05 15:13:37]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
using ui = unsigned int;
using ull = unsigned long long;
using ll = long long;
#define endl '\n'
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int maxn = 2e5 + 10;
const int mod = 1000000007;
#define inl inline
#define fr(i, a, b) for (int i = a; i <= b; i++)
#define ford(i, a, b) for (int i = a; i >= b; i--)
#define forall(i, a) for (auto &i : a)

/**
   ____         ___ _____
  / ___| _   _ / _ \___ /
  \___ \| | | | | | ||_ \
   ___) | |_| | |_| |__) |
  |____/ \__, |\___/____/
         |___/
*/
istream &operator>>(istream &in, vector<int> &v)
{
    for (auto &i : v)
        in >> i;
    return in;
}
ostream &operator<<(ostream &out, vector<int> &v)
{
    for (auto &i : v)
        out << i << " ";
    return out;
}
bool _output = 1;

int ans = -1;
bool suc = 0;
int query(int l, int r)
{

    cout << "? " << l << " " << r << endl;
    int x;
    cin >> x;
    return x;
}
int make(int l, int r, int t)
{
    // cout << "Debug  =  " << l << " " << r << " " << t << endl;
    if (suc)
    {
        return ans;
    }
    if (r - l == 0)
    {
        suc = 1;
        return l;
    }
    else if (r - l == 1)
    {
        suc = 1;
        return r + l - t;
    }
    if (t <= (l + r) / 2)
    {
        int mid = (2 * r + l) / 3;
        int s = query(l, mid);
        if (suc)
        {
            return ans;
        }
        if (s == t)
        {
            return make(l, mid, s);
        }
        else
        {
            int x = query(mid + 1, r);
            if (suc)
                return ans;
            return make(mid + 1, r, x);
        }
    }
    else
    {
        int mid = (2 * l + r + 2) / 3;
        int s = query(mid, r);
        if (s == t)
        {
            return make(mid, r, s);
        }
        else
        {
            int x = query(l, mid - 1);
            if (suc)
                return ans;
            return make(l, mid - 1, x);
        }
    }
    if (suc)
    {
        return ans;
    }
}

void solve()
{
    suc = 0;
    ans = -1;
    int n;
    cin >> n;
    int t = query(1, n);
    int ans = make(1, n, t);
    // assert(ans != -1);
    cout << "! " << ans << endl;
}
signed main()
{
    int _ = 1;
    if (_output)
        cin >> _;
    while (_--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
5
3
2
5
6
6
3
1
4
3
3
2

output:

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

result:

wrong answer Too many queries , n = 4 , now_q 4 (test case 3)