QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#107548#6394. Turn on the LightwsyearWA 3ms3512kbC++171.6kb2023-05-21 22:34:422023-05-21 22:34:43

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-21 22:34:43]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3512kb
  • [2023-05-21 22:34:42]
  • 提交

answer

#include <bits/stdc++.h>
#ifdef dbg
#define D(...) fprintf(stderr, __VA_ARGS__)
#define DD(...) D(#__VA_ARGS__ " = "), debug_helper::debug(__VA_ARGS__), D("\n")
#include "C:\Users\wsyear\Desktop\OI\templates\debug.hpp"
#else
#define D(...) ((void)0)
#define DD(...) ((void)0)
#endif
#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define gc getchar
#define pc putchar
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

using namespace std;

template <class T = int> T read() {
  T x = 0; bool f = 0; char ch = gc();
  while (!isdigit(ch)) f = ch == '-', ch = gc();
  while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = gc();
  return f ? -x: x;
}
template <class T> void write(T x) {
  if (x >= 0) { if (x > 9) write(x / 10); pc(x % 10 + 48); }
  else { pc('-'); if (x < -9) write(-x / 10); pc(48 - x % 10); }
}

int n;

int ask(int x) {
  printf("? %d\n", x), fflush(stdout);
  return read();
}

void rpt(int x) {
  printf("! %d\n", x), fflush(stdout);
}

int main() {
  n = read();
  int l = 2, r = n, lst = ask(1);
  if (!lst) return rpt(1), 0;
  while (l <= r) {
    int mid = (l + r) >> 1;
    int cur = ask(mid);
    if (cur == lst) return rpt(mid), 0;
    if (cur > lst) l = mid + 1;
    else r = mid - 1;
    lst = cur;
    if (l < r && lst != 0) {
      cur = ask(l);
      if (cur == lst) return rpt(l), 0;
      l++, lst = cur;
    }
  }
  rpt(l);
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 3512kb

input:

3
1
2
2

output:

? 1
? 2
? 3
! 3

result:

ok Correct position at 3

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 3464kb

input:

10
1
0
1
2
3

output:

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

result:

wrong answer Wrong favorite light!