Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cmath>
- int* mas;
- using namespace std;
- int main()
- {
- cout.flush();
- int n, h, check = 0;
- scanf("%d", &n);
- if (n <= 0)
- {
- printf("!");
- printf(" %d", 0);
- check = 1;
- }
- if (check == 0)
- {
- mas = new int[n+1];
- for (int i = 1; i <= n+1; i++)
- {
- mas[i] = -1;
- }
- int l, r, m, ans;
- l = 1;
- r = n;
- while (l - r < 0)
- {
- m = (l + r + 1) / 2;
- if (mas[m] >= 0)
- h = mas[m];
- else
- {
- printf("? %d\n", m);
- fflush(stdout);
- scanf("%d", &h);
- mas[m] = h;
- }
- mas[m] = h;
- if (h <= 0)
- {
- l = m;
- }
- else
- {
- r = m - 1;
- }
- }
- if (mas[l] != -1)
- h = mas[l];
- else
- {
- printf("? %d\n", l);
- fflush(stdout);
- scanf("%d", &h);
- }
- if (h == 0)
- {
- ans = n - l;
- }
- if (h == 1)
- {
- ans = n;
- }
- printf("!");
- printf(" %d", ans);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement