fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6.  
  7.  
  8. const int M = 1000000007;
  9. const int N = 3e5+9;
  10. const int INF = 2e9+1;
  11. const int LINF = 2000000000000000001;
  12.  
  13. inline int power(int a, int b, int mod=M) {
  14. int x = 1;
  15. a %= mod;
  16. while (b) {
  17. if (b & 1) x = (x * a) % mod;
  18. a = (a * a) % mod;
  19. b >>= 1;
  20. }
  21. return x;
  22. }
  23.  
  24.  
  25. //_ ***************************** START Below *******************************
  26.  
  27. //* Change this to false => before submitting to cf
  28. // bool testing = true;
  29. bool testing = false;
  30.  
  31.  
  32. vector<int> a = {INF, 2, 4, 3, 7, 10, 11, 1, 9, 8, 6, 5};
  33.  
  34. int interactor(int i){
  35. return a[i];
  36. }
  37.  
  38. //* n = 11
  39. //* [ inf 2 4 3 7 10 11 1 9 8 6 5 inf ]
  40.  
  41.  
  42. int askQuery(int x){
  43. cout << "? " << x << endl;
  44.  
  45. if(testing){
  46. cout << interactor(x) << endl;
  47. return interactor(x);
  48. }
  49. int y;
  50. cin >> y;
  51. return y;
  52.  
  53. }
  54.  
  55.  
  56. int consistency(){
  57.  
  58. int n;
  59. cin >> n;
  60.  
  61.  
  62. int s = 1, e = n;
  63. int ans = -1;
  64.  
  65. while(s<=e){
  66. int mid = s + (e-s)/2;
  67.  
  68.  
  69. int res = askQuery(mid);
  70. int left = mid-1 == 0 ? INF : askQuery(mid-1);
  71. int right = mid+1 == n+1 ? INF : askQuery(mid+1);
  72.  
  73. if(left > res && res < right){
  74. ans = mid;
  75. break;
  76. }
  77. if(left > res ){
  78. s = mid+1;
  79. }
  80. else{
  81. e = mid-1;
  82. }
  83.  
  84. }
  85.  
  86. return ans;
  87. }
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96. void solve() {
  97.  
  98. int ans = consistency();
  99. cout << "! " << ans << endl;
  100.  
  101. }
  102.  
  103.  
  104.  
  105.  
  106.  
  107. int32_t main() {
  108. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  109.  
  110. solve();
  111.  
  112. return 0;
  113. }
Success #stdin #stdout 0s 5324KB
stdin
11
stdout
? 6
11
? 5
10
? 7
1
? 3
3
? 2
4
? 4
7
! 3