QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#557153#8939. Permutationnhuang685WA 1ms3636kbC++231.3kb2024-09-11 05:57:542024-09-11 05:57:54

Judging History

This is the latest submission verdict.

  • [2024-09-11 05:57:54]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3636kb
  • [2024-09-11 05:57:54]
  • Submitted

answer

/**
 * @author n685
 * @brief
 * @date 2024-09-10 17:43:29
 *
 *
 */
#include "bits/stdc++.h"

#ifdef LOCAL
#include "dd/debug.h"
#else
#define dbg(...) 42
#define dbg_proj(...) 420
#define dbg_rproj(...) 420420
void nline() {}
void bar() {}
void start_clock() {}
void end_clock() {}
#endif

namespace rs = std::ranges;
namespace rv = std::views;

int query(int l, int r) {
  std::cout << std::format("? {} {}\n", l, r) << std::flush;
  int ind;
  std::cin >> ind;
  return ind;
}

void solve() {
  int n;
  std::cin >> n;

  int l = 1, r = n;
  int sec = -1;
  while (l < r) {
    if (sec == -1) {
      sec = query(l, r);
    }
    if (r - l == 1) {
      if (l == sec) {
        l = r;
      } else {
        r = l;
      }
      break;
    }
    int sz = 3 * (r - l + 1) / 5;
    if (sec <= l + sz - 1) {
      int ind = query(l, l + sz - 1);
      if (ind == sec) {
        r = l + sz - 1;
      } else {
        l += sz;
        sec = -1;
      }
    } else {
      int ind = query(r - sz + 1, r);
      if (ind == sec) {
        l = r - sz + 1;
      } else {
        r -= sz;
        sec = -1;
      }
    }
  }
  std::cout << std::format("! {}\n", l) << std::flush;
}

int main() {
  int t;
  std::cin >> t;
  for (int i = 0; i < t; ++i) {
    dbg(i + 1);
    solve();
    bar();
  }
}

詳細信息

Test #1:

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

input:

3
5
3
2
5
6
6
5
3

output:

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

result:

wrong answer Integer 3 violates the range [4, 6] (test case 2)