QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#563822#8939. Permutationucup-team3691#WA 8ms3648kbC++142.5kb2024-09-14 16:10:042024-09-14 16:10:05

Judging History

This is the latest submission verdict.

  • [2024-09-14 16:10:05]
  • Judged
  • Verdict: WA
  • Time: 8ms
  • Memory: 3648kb
  • [2024-09-14 16:10:04]
  • 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 l = 1, r = n;
  cout << "? " << l << " " << r << endl;

  int x, y;
  cin >> x;

  while (r - l > 2) {
    int mid = (l + r) / 2;
    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) - l - oth << endl;
    }
  }

}

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

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

  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3616kb

input:

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

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 8ms
memory: 3648kb

input:

10000
10
2
2
3
5
10
10
10
9
7
7
10
5
1
10
9
6

output:

? 1 10
? 1 5
? 1 3
? 4 5
! 4
? 1 10
? 6 10
? 9 10
? 6 8
? 6 7
! 6
? 1 10
? 1 5
? 6 10
? 9 10
? 6 8
? 6 7

result:

wrong answer Too many queries , n = 10 , now_q 6 (test case 3)