QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#776788#8239. Mysterious TreedodolaTL 0ms0kbC++171.8kb2024-11-23 20:59:342024-11-23 20:59:35

Judging History

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

  • [2024-11-23 20:59:35]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-11-23 20:59:34]
  • 提交

answer

#include <bits/stdc++.h>
#include <utility>

#define x first
#define y second

using namespace std;

typedef double ld;
typedef unsigned long ul;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;

const int maxn = 3e5 + 50;
const ll inf = 0x3f3f3f3f3f3f;
const vector<pll> dxy = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};

void solve() {
  ll n;
  cin >> n;

  ll t;
  auto ask = [&](ll p1, ll p2) {
    cout << "? " << p1 << ' ' << p2 << endl;
    cin >> t;
  };
  auto conf = [&](ll x) { cout << "! " << x << endl; };

  bool flag = false;
  ll u = -1, v = -1;
  for (ll i = 1; i + 1 <= n; i += 2) {
    ask(i, i + 1);
    if (t == 1) {
      flag = true;
      u = i, v = i + 1;
      break;
    }
  }

  ll t1, t2, t3;
  if (!flag) {
    if (n & 1) {
      ask(n, 1);
      t1 = t;
      ask(n, 2);
      t2 = t;
      ask(n, 3);
      t3 = t;
      if (t1 && t2 && t3) {
        conf(2);
      } else {
        conf(1);
      }
    } else {
      conf(1);
    }
    return;
  }
  if (u - 1 >= 1) {
    ask(u - 1, u);
    t1 = t;
    if (t1 != 1) {
      ask(u - 1, v);
      t2 = t;
      if (t2 != 1) {
        conf(1);
      } else {
        if (v + 1 <= n)
          ask(v, v + 1);
        else
          ask(u - 2, v);
        t3 = t;
        if (t3 != 1) {
          conf(1);
        } else {
          conf(2);
        }
      }
    } else {
      if (u - 2 >= 1) {
        ask(u - 2, u);
      } else {
        ask(v + 1, u);
      }
      t2 = t;
      if (t2 != 1) {
        conf(1);
      } else {
        conf(2);
      }
    }
  }
}

void init() {}

int main(void) {
  // ios::sync_with_stdio(false);
  // cin.tie(0);
  init();
  int _t = 1;
  cin >> _t;
  cin.get();
  while (_t--)
    solve();

  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

2
4
1

output:

? 1 2

result: