Submission #747085

#TimeUsernameProblemLanguageResultExecution timeMemory
747085MilosMilutinovicMađioničar (COI22_madionicar)C++14
100 / 100
1847 ms208 KiB
/**
 *    author:  wxhtzdy
 *    created: 05.07.2022 14:44:38
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);  
  int n;
  cin >> n;
  auto Ask = [&](int l, int r) {
    cout << "? " << l + 1 << " " << r + 1 << endl;
    int x;
    cin >> x;
    return x; 
  };
  int ans = 1;
  for (int i = 1; i < n; i++) {
    while (true) {
      int l = i - (ans + 1) / 2;
      int r = i + (ans + 1) / 2;
      if (l < 0 || r >= n || !Ask(l, r)) {
        break;
      }
      ans = r - l + 1;
    }
  }
  for (int i = 0; i + 1 < n; i++) {
    while (true) {
      int l = i - (ans % 2 == 1 ? (ans - 1) / 2 : ans / 2);
      int r = i + 1 + (ans % 2 == 1 ? (ans - 1) / 2 : ans / 2);
      if (l < 0 || r >= n || !Ask(l, r)) {
        break;
      }
      ans = r - l + 1;
    }
  }
  cout << "! " << ans << endl;                  
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...