Submission #1274456

#TimeUsernameProblemLanguageResultExecution timeMemory
1274456huhuhuhuhuMađioničar (COI22_madionicar)C++20
In queue
0 ms0 KiB
#include <bits/stdc++.h>

using namespace std;
bool palin(long long l, long long r) {
  // cout << "HUH" << endl;
  cout << "? " << l + 1 << " " << r + 1 << endl;
  cout << flush;
  long long ans = 0;
  cin >> ans;
  return ans == 1;
}

long long pSize[200005];
long long n;

int main() {
  cin >> n;
  long long center = 0, right = -1;
  long long ans = 0;
  // cout << "hi" << endl;
  for (int i = 0; i < n*2+1; i++) {
    if (i > right) {
      center = i;
      right = i;
      long long newRight = i + 1;
      while (right < 2 * n + 1) {
        long long left = 2 * center - newRight;
        if (left < 0) {
          break;
        }
        if (newRight % 2 == 1 && !palin(left/2, newRight/2)) {
          break;
        }
        right = newRight;
        newRight++;
      }
      pSize[i] = right - center + 1;
    } else if (i <= right) {
      bool recalc = false;
      long long mirror = 2 * center - i;
      long long newBound;
      
      if (mirror < 0) {
        newBound = i;
        recalc = true;
      } else {
        newBound = i + pSize[mirror] - 1;
      }

      if (recalc || newBound >= right) {
        center = i;
        right = newBound;
        long long newRight = newBound + 1;
        while (newRight < 2 * n + 1) {
          long long left = 2 * center - newRight;
          if (left < 0) {
            break;
          }
          if (newRight % 2 == 1 && !palin(left/2, newRight/2)) {
            break;
          }
          right = newRight;
          newRight++;
        }
        // cout << center << " " << right << endl;
        pSize[i] = right - center + 1;
      } else {
        pSize[i] = pSize[mirror];
      }
      // cout << i << " ";
    }
    // cout << pSize[i] << " " << (i % 2 == 1 ? test[i/2] : '#') << endl;
    if (i%2 == 0) {
      ans = max(ans, 2 * (pSize[i]/2));
    } else {
      ans = max(ans, 2 * (pSize[i]/2) - 1);
    }
  }
  cout << "! " << ans << endl;
  cout << flush;
}