fork download
  1. // TEMPLATE - START
  2. // ----------------------------------------------------
  3. using namespace std;
  4. // ----------------------------------------------------
  5. // DEFINES - START
  6. #include <bits/stdc++.h>
  7. #define FAST \
  8.   ios_base::sync_with_stdio(0); \
  9.   cin.tie(0); \
  10.   cout.tie(0);
  11. // Strings
  12. #define nl endl
  13. #define bl cout << endl
  14. #define YES cout << "YES\n"
  15. #define NO cout << "NO\n"
  16. #define yn(x) \
  17.   if (x) \
  18.   YES; \
  19.   else \
  20.   NO;
  21. #define yns(x, s1, s2) \
  22.   if (x) \
  23.   cout << s1 << "\n"; \
  24.   else \
  25.   cout << s2 << "\n";
  26. #define fail(cond) \
  27.   if (cond) \
  28.   return void(NO);
  29. #define success(cond) \
  30.   if (cond) \
  31.   return void(YES);
  32. #define fail(cond, s) \
  33.   if (cond) \
  34.   return void(cout << s << nl);
  35. #define success(cond, s) \
  36.   if (cond) \
  37.   return void(cout << s << nl);
  38. // Types
  39. #define ll long long
  40. #define ld long double
  41. #define ull unsigned long long
  42. #define vl vector<ll>
  43. #define pll pair<ll, ll>
  44. #define vpll vector<pair<ll, ll>>
  45. #define all(x) (x).begin(), (x).end()
  46. #define rall(x) (x).rbegin(), (x).rend()
  47. // Loops
  48. #define lp(i, a, b) for (int i = (a); i < (b); i++)
  49. #define rlp(i, a, b) for (int i = (b) - 1; i >= (a); i--)
  50. #define readlp(arr, n) \
  51.   lp(i, 0, n) cin >> arr[i];
  52. #define writelp(arr, n) \
  53.   lp(i, 0, n) cout << arr[i] << " "; \
  54.   bl;
  55. #define write(v) \
  56.   for (auto x : v) \
  57.   cout << x << " "; \
  58.   bl;
  59. #define vv \
  60.   ll n; \
  61.   cin >> n; \
  62.   vl v(n); \
  63.   readlp(v, v.size());
  64. // DEFINES - END
  65. // ----------------------------------------------------
  66. // DATA_STRUCTURES - START
  67. #include <ext/pb_ds/assoc_container.hpp>
  68. #include <ext/pb_ds/tree_policy.hpp>
  69.  
  70. using namespace __gnu_pbds;
  71.  
  72. // Ordered set (no duplicates, ordered by Key)
  73. template <class Key>
  74. using ordered_set = tree<Key, null_type, less<Key>, rb_tree_tag, tree_order_statistics_node_update>;
  75.  
  76. // Ordered multi-set (allows duplicates, ordered by Key)
  77. template <class Key>
  78. using ordered_multi_set = tree<Key, null_type, less_equal<Key>, rb_tree_tag, tree_order_statistics_node_update>;
  79.  
  80. // Ordered map (Key -> Value, ordered by Key)
  81. template <class Key, class Val>
  82. using ordered_map = tree<Key, Val, less<Key>, rb_tree_tag, tree_order_statistics_node_update>;
  83. // DATA_STRUCTURES - END
  84. // ----------------------------------------------------
  85. // ALGORITHMS - START
  86. // Binary Search Custom:
  87. // To Find...,Logical Condition,If Condition is Met...,Return Value
  88. // Lower Bound (First element ≥x),arr[m] >= x,r = m,r
  89. // Upper Bound (First element >x),arr[m] > x,r = m,r
  90. // Last element <x,arr[m] < x,l = m,l
  91. // Last element ≤x,arr[m] <= x,l = m,l
  92.  
  93. ll lowerBound(vector<ll> &v, ll x)
  94. {
  95. ll l = -1, r = v.size();
  96. while (r > l + 1)
  97. {
  98. ll m = l + (r - l) / 2;
  99. ll curr = v[m];
  100. if (curr >= x)
  101. r = m;
  102. else
  103. l = m;
  104. }
  105. return r;
  106. }
  107. // ALGORITHMS - END
  108. // ----------------------------------------------------
  109. // TEMPLATE END
  110.  
  111. // ====================================================
  112.  
  113. // Boody's Code
  114. // 2026-08-17, 15:49:32
  115. // Codeforces - The 2026 ICPC Egyptian Collegiate Programming Contest (Qualifications - Day 5)
  116. // L. The Blind Artillery
  117. // https://c...content-available-to-author-only...s.com/group/Rilx5irOux/contest/710922/problem/L
  118. // Time limit: 00, Memory limit: 5
  119. // status:
  120. // Time taken:2
  121.  
  122. // ----------------------------------------------------
  123. ll lo, m1, m2, hi;
  124. ll ans1 = -1, ans2 = -1;
  125.  
  126. pll f(ll t)
  127. {
  128. cout << "? " << t << nl;
  129. ll p, d;
  130. cin >> p >> d;
  131. return {p, d};
  132. }
  133.  
  134. void lowerBoundt()
  135. {
  136. ll l = lo - 1, r = hi + 1;
  137. while (r > l + 1)
  138. {
  139. ll m = l + (r - l) / 2;
  140. pll curr = f(m);
  141. if (curr.first == -1)
  142. {
  143. if (curr.second == 1)
  144. lo = m + 1, l = m;
  145. else
  146. hi = m - 1, r = m;
  147. }
  148. else if (curr.first == 1)
  149. {
  150. m1 = m - 1, m2 = m + 1;
  151. break;
  152. }
  153. else
  154. {
  155. if (curr.second == 1)
  156. ans1 = m, m2 = m + 1, m1 = m;
  157. else
  158. ans2 = m, m1 = m - 1, m2 = m;
  159. break;
  160. }
  161. }
  162. }
  163.  
  164. ll lowerBoundt1(ll s, ll e)
  165. {
  166. ll l = s - 1, r = e + 1;
  167. while (r > l + 1)
  168. {
  169. ll m = l + (r - l) / 2;
  170. pll curr = f(m);
  171. if (curr.first == 0)
  172. r = m, l = m - 1;
  173. else if (curr.first == -1)
  174. l = m;
  175. else
  176. r = m;
  177. }
  178. return r;
  179. }
  180.  
  181. ll lowerBoundt2(ll s, ll e)
  182. {
  183. ll l = s - 1, r = e + 1;
  184. while (r > l + 1)
  185. {
  186. ll m = l + (r - l) / 2;
  187. pll curr = f(m);
  188. if (curr.first == 0)
  189. l = m, r = m + 1;
  190. else if (curr.first == -1)
  191. r = m;
  192. else
  193. l = m;
  194. }
  195. return l;
  196. }
  197.  
  198. void solve()
  199. {
  200. lo = 1, hi = 1e9, ans1 = -1, ans2 = -1;
  201. lowerBoundt();
  202. if (ans1 == -1)
  203. ans1 = lowerBoundt1(lo, m1);
  204. if (ans2 == -1)
  205. ans2 = lowerBoundt2(m2, hi);
  206. cout << "! " << ans1 << " " << ans2 << nl;
  207. }
  208.  
  209. int main()
  210. {
  211. #ifndef ONLINE_JUDGE
  212. freopen("/home/rodex/rubuntu/CS/CP/input.txt", "r", stdin);
  213. freopen("/home/rodex/rubuntu/CS/CP/output.txt", "w", stdout);
  214. #endif
  215. FAST;
  216.  
  217. int t = 1;
  218. cin >> t;
  219. while (t--)
  220. solve();
  221. }
  222.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
? 500000000
? 250000000
? 125000000
? 62500000
? 31250000
? 15625000
? 7812500
? 3906250
? 1953125
? 976562
? 488281
? 244140
? 122070
? 61035
? 30517
? 15258
? 7629
? 3814
? 1907
? 953
? 476
? 238
? 119
? 59
? 29
? 14
? 7
? 3
? 1
! 1 500000000