QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#563867#8939. Permutationucup-team3691#WA 0ms3580kbC++142.6kb2024-09-14 16:31:202024-09-14 16:31:20

Judging History

This is the latest submission verdict.

  • [2024-09-14 16:31:20]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3580kb
  • [2024-09-14 16:31:20]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
using namespace chrono;

using ll = long long;
using ull = unsigned long long;

string to_string(const string &s) {
  return '"' + s + '"';
}

string to_string(bool b) {
  return b ? "true" : "false";
}

template <typename A, typename B>
string to_string(const pair<A, B> &p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename T>
string to_string(const T &v) {
  string s = "{";
  bool first = true;
  for (const auto &it : v) {
    if (!first)
      s += ", ";
    else
      first = false;
    s += to_string(it);
  }
  return s += "}";
}

void debug_out() {
  cerr << endl;
}

template <typename T, typename... Args>
void debug_out(const T &first, const Args&... rest) {
  cerr << to_string(first) << " ";
  debug_out(rest...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

auto startTime = high_resolution_clock::now();
int get_time() {
  auto stopTime = chrono::high_resolution_clock::now();
  auto duration = duration_cast<milliseconds>(stopTime - startTime);
  return duration.count(); // in ms
}

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

  int x, y;
  int l = 1, r = n;

  cout << "? " << l << " " << r << endl;

  cin >> x;

  while (r - l > 2) {
    int mid = l + 2 * (r - l) / 3;
    if (x > mid) {
      mid = r - 2 * (r - l) / 3; 
    }

    if (x <= mid) {
      cout << "? " << l << " " << mid << endl; 
    } else {
      cout << "? " << mid + 1 << " " << r << endl; 
    }
    cin >> y;

    if (x != y) {
      if (x <= mid) {
        cout << "? " << mid + 1 << " " << r << endl; 
        l = mid + 1;
      } else {
        cout << "? " << l << " " << mid << endl; 
        r = mid;
      }
      cin >> x;
    } else {
      if (x <= mid) {
        r = mid;
      } else {
        l = mid + 1;
      }
    }
  }

  if (r - l == 0) {
    cout << "! " << l << endl;
  } else if (r - l == 1) {
    cout << "! " << (r + l) - x << endl;
  } else if (r - l == 2) {
    int oth = l + 1;
    if (x == oth) {
      oth = l;
    }

    cout << "? " << min(oth, x) << " " << max(x, oth) << endl;

    cin >> y;
    if (x == y) {
      cout << "! " << oth << endl;
    } else {
      cout << "! " << (l + l + 1 + l + 2) - x - oth << endl;
    }
  }

}

int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);

  int t = 1;
  cin >> t;
  while (t--)
    solve();

  return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3580kb

input:

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

output:

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

result:

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