Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cmath>
- using namespace std;
- int mas[10000000];
- bool boo[10000000];
- int ans = 0;
- int search(int* mas, int l, int r)
- {
- cout.flush();
- int h, zl, zr;
- if (r < l)
- {
- return (l-1);
- }
- int mid = (l + r) / 2;
- if (boo[mid] == false)
- {
- cout << "? " << mid << endl;
- cin >> h;
- mas[mid] = h;
- boo[mid] = true;
- }
- else
- h = mas[mid];
- if (mas[mid] >= mid)
- return search(mas, l, mid - 1);
- else
- return search(mas, mid + 1, r);
- }
- int main()
- {
- int l, r, m;
- int n;
- cin >> n;
- int k;
- l = 1;
- r = n;
- for (int i = 1; i <= n + 1; i++)
- {
- mas[i] = -1;
- }
- for (int i = 0; i < n * 2; i++)
- {
- boo[i] = false;
- }
- cout << "! " << search(mas, l, r) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement