Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. long long get(int n) {
  6. cout << "? " << n << "\n";
  7. fflush(stdout);
  8. long long x;
  9. cin >> x;
  10. return x;
  11. }
  12.  
  13. long long sum(int n) {
  14. return n * (n + 1LL) / 2;
  15. }
  16.  
  17. int main() {
  18. //freopen("input.txt", "r", stdin);
  19. //freopen("output.txt", "w", stdout);
  20.  
  21. int n;
  22. cin >> n;
  23.  
  24. int l = 0, r = n;
  25. while (l + 1 < r) {
  26. int m = l + (r - l) / 2;
  27. if (get(m) == sum(m))
  28. l = m;
  29. else
  30. r = m;
  31. }
  32. int res1 = r;
  33.  
  34. int sum23 = sum(n) - get(n) - res1;
  35. int half23 = sum23 / 2;
  36.  
  37. int res2 = sum(half23) - get(half23);
  38. if (res1 <= half23)
  39. res2 -= res1;
  40.  
  41. int res3 = sum23 - res2;
  42.  
  43. cout << "! " << res1 << " " << res2 << " " << res3 << "\n";
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement