fork 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;
  33.  
  34. void hack(int n){
  35. a.resize(n+1);
  36. for(int i=1; i<=n; i++) cin >> a[i];
  37. }
  38.  
  39. int interactor(int i){
  40. return a[i];
  41. }
  42.  
  43.  
  44.  
  45. int askQuery(int x){
  46. cout << "? " << x << endl;
  47.  
  48. if(testing){
  49. cout << interactor(x) << endl;
  50. return interactor(x);
  51. }
  52. int y;
  53. cin >> y;
  54. return y;
  55.  
  56. }
  57.  
  58.  
  59. int consistency(int n){
  60.  
  61. if(testing){
  62. hack(n);
  63. }
  64.  
  65. int s = 1, e = n;
  66. int ans = -1;
  67.  
  68. while(s<=e){
  69. int mid = s + (e-s)/2;
  70.  
  71.  
  72. int res = askQuery(mid);
  73. int left = mid-1 == 0 ? INF : askQuery(mid-1);
  74. int right = mid+1 == n+1 ? INF : askQuery(mid+1);
  75.  
  76. if(left > res && res < right){
  77. ans = mid;
  78. break;
  79. }
  80. if(left > res ){
  81. s = mid+1;
  82. }
  83. else{
  84. e = mid-1;
  85. }
  86.  
  87. }
  88.  
  89. return ans;
  90. }
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99. void solve() {
  100. int n;
  101. cin >> n;
  102.  
  103. int ans = consistency(n);
  104. cout << "! " << ans << endl;
  105.  
  106. }
  107.  
  108.  
  109.  
  110.  
  111.  
  112. int32_t main() {
  113. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  114.  
  115. int t = 1;
  116. // cin >> t;
  117. while(t--){
  118. solve();
  119. }
  120.  
  121.  
  122. return 0;
  123. }
Success #stdin #stdout 0s 5320KB
stdin
11
2 4 3 7 10 11 1 9 8 6 5
stdout
? 6
11
? 5
10
? 7
1
? 3
3
? 2
4
? 4
7
! 3