QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#131685#6394. Turn on the LightClHg2WA 1ms3484kbC++141.7kb2023-07-27 20:57:402023-07-27 20:57:42

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-27 20:57:42]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3484kb
  • [2023-07-27 20:57:40]
  • 提交

answer

#include <array>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>

namespace {
using std::cin;
using std::cout;
using std::endl;
using std::int64_t;
using std::size_t;

namespace base {
template <typename T, size_t... sizes>
struct NestedArray {};

template <typename T, size_t size, size_t... sizes>
struct NestedArray<T, size, sizes...> {
  using Type = std::array<typename NestedArray<T, sizes...>::Type, size>;
};

template <typename T>
struct NestedArray<T> {
  using Type = T;
};

template <typename T, size_t... sizes>
using Array = typename NestedArray<T, sizes...>::Type;

void OptimizeIO() {
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
}

void OptimizeIO(const std::string &input_file, const std::string &output_file) {
  static std::ifstream input_stream(input_file);
  static std::ofstream output_stream(output_file);
  cin.rdbuf(input_stream.rdbuf()), cout.rdbuf(output_stream.rdbuf());
  cin.tie(nullptr), cout.tie(nullptr);
}
}  // namespace base

using base::Array;

int Query(int x) {
  cout << "? " << x << endl;
  int res;
  cin >> res;
  return res;
}

void Answer(int x) {
  cout << "! " << x << endl;
  std::exit(0);
}

int Main() {
  base::OptimizeIO();
  int n;
  cin >> n;
  int l = 1, r = n, cur = 1, last = 0;

  while (l <= r) {
    int res = Query(cur);
    if (res == last) Answer(cur);
    ++cur, last = res;
    if (cur > l) l = cur;

    int mid = (l + r) >> 1;
    res = Query(mid);
    if (res == last) Answer(mid);
    res < last ? r = mid - 1 : l = mid + 1;
    last = res;
  }

  __builtin_unreachable();
  return 0;
}
}  // namespace

int main() { return Main(); }

详细

Test #1:

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

input:

3
1
2
2

output:

? 1
? 2
? 2
! 2

result:

wrong answer Wrong favorite light!